0

プロパティ ファイルへの絶対パスを指定するにはどうすればよいですか。

autoamtion_environment_properties = new Properties();
InputStream iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(("C:\\automation_environment.properties"));

これは を与えていnull pointer exceptionます。

このファイルがプロジェクトのルート フォルダーにある場合は機能しますが、外部からアクセスする必要があります。何をする必要があるか考えていますか?

ありがとう。

4

4 に答える 4

3

ファイルが機能するには、ファイルが CLASSPATH にある必要があります。IDE が問題を解決してくれますが、松葉杖がない場合は、自分が何をしているのかを知る必要があります。.properties ファイルが存在するディレクトリを CLASSPATH に含めます。

于 2012-09-27T21:12:18.233 に答える
1

ファイルのフルパスがわかっている場合は、FileInputStreamクラスを使用できます

InputStream iStream = new FileInputStream(new File("C:\\automation_environment.properties"));

それ以外の場合は、この回答を参照してくださいhttps://stackoverflow.com/a/676273/176569

于 2012-09-27T21:16:58.493 に答える
0

次のように \ を / に設定しようとします。 InputStream iStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(("C:/automation_environment.properties"));

于 2012-09-27T21:20:12.230 に答える
0

クレイジーな Thread の代わりに FileInputStream を使用しないのはなぜですか?

InputStream in = new FileInputStream(new File("C:\\automation_environment.properties"));

http://docs.oracle.com/javase/6/docs/api/java/io/FileInputStream.html

于 2012-09-27T21:13:26.630 に答える