2017-05-19 1 views
0

Javaプログラムを起動すると、外部のfile.propertiesをロードしようとしていますが、ファイルをロードしません。 私はこのプログラムと私のデスクトップにfile.propertiesを持っています。 これはWebアプリケーションではありません。Javaプロジェクトと外部ファイルfil.properties

私もクラスパスとパスとしてPC上の環境変数を設定しているが、私はプログラムを実行すると、それは彼らを見ていない

String filePath = "file.properties"; 
Properties data = new Properties(); 
    try{ 

     FileInputStream stream = new FileInputStream(new File(filePath)); 
     data.load(stream); 
     execute(args,data); 

    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 

が、これは誤りです:

java.io.FileNotFoundException: file.properties (Impossibile trovare il file specificato.) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:137) at it.applications.AssCitRice.ParseXmlSct.(ParseXmlSct.java:42) at it.applications.AssCitRice.ParseXmlSct.main(ParseXmlSct.java:286) log4j:WARN No appenders could be found for logger (it..applications.AssegniCitRicezionePresentazione.ParseXmlSct). log4j:WARN Please initialize the log4j system properly.

ヘルプ私にしてください

+0

'FileNotFoundException'。 filePathを確認してください。正しくないようですか? – kkflf

+0

はいパスが正しい.. :( – Vins

+0

ParseXmlSctがクラス名であると仮定します。そのファイルの42行目は何ですか? – kkflf

答えて

0

あなたは正しい(完全な)パス名を使用する必要がありました:

String filePath = APLHOME + File.separator + "file.properties"; 
or 
String filePath = System.getenv("APLHOME") + File.separator + "file.properties"; 

は、基本的にはどちらかのファイルが存在しないか、間違ったパスを提供してきたことを意味し、クラスパス

0

FileNotFoundExceptionに見えるようにテキストファイルを開くにはメカニズムがありません。

絶対パスを指定する必要があります。さもなければ、Javaはそれを見つけることができません。

//The below will work great as long as the file exists in that path. 
FileInputStream stream = new FileInputStream(new File("C:/test.txt")); 

//This will however not work 
FileInputStream stream = new FileInputStream(new File("/test.txt")); 
関連する問題