SORU
2 EKİM 2010, CUMARTESİ


Nasıl bir proje göreli yol metin dosyası okumak için?

2 paket ile bir projem var:

  1. tkorg.idrs.core.searchengines
  2. tkorg.idrs.core.searchengines

Paket (2) metin (1) 8 ** Dersim var paket ListStopWords.txt, dosya. Burada FileLoader kod:

File file = new File("properties\\files\\ListStopWords.txt");

Ama bu hata var:

The system cannot find the path specified

Bir çözüm tamir EDEBİLİR MİSİN? Teşekkürler.

CEVAP
2 EKİM 2010, CUMARTESİ


Eğer zaten bir sınıf ise, o zaman sadece bir sınıf, onu almak. java.io.File göreli yolları ile keman yok. Hangi tamamen Java kodu içinde herhangi bir kontrolü var, geçerli çalışma dizini bağlıdır.

ListStopWords.txt FileLoader sınıfla aynı pakette olduğunu varsayarsak:

URL url = getClass().getResource("ListStopWords.txt");
File file = new File(url.getPath());

Ya da eğer tüm sonra o InputStream bir:

InputStream input = getClass().getResourceAsStream("ListStopWords.txt");

Eğer dosya ise paket ipuçları - adıaslındasadece 15 ** fullworthy (key=value çizgiler içeren) "" o zaman hemen load() yöntemi yem olabilir uzantısı. yanlış

Properties properties = new Properties();
properties.load(getClass().getResourceAsStream("ListStopWords.txt"));

Not: static bağlam içinden erişmeye çalıştığınız zaman, o zaman yukarıdaki örneklerde FileLoader.class yerine getClass() kullanın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ImBluecams

    ImBluecams

    25 Kasım 2012
  • PCDIY

    PCDIY

    16 AĞUSTOS 2013
  • TheDailyTechDose

    TheDailyTech

    15 EKİM 2012