0

I have a project in eclipse where all my source code is under mbl/src. I am exporting this code as a runnable jar. I have got another folder under mbl/files which contains some of the properties files.I want to export these files also but eclipse doesnt give any such option. I have put the mbl/files under add class folder in build path options but still I am facing similar issues. I have also put the files folder directly under src folder but still it is not able to access it.I am using following options in commandline.

java -jar myprogram.jar arg1

It gives this error:

Unable to find files/text1.properties

text1.properties is under mbl/files/text1.properties

and is referred in the following manner from main class:

FileInputStream fs=new FileInputStream("files\\text1.properties");
4

1 に答える 1

0

Jar 内に埋め込まれたリソースは、Class.getResource(...)メソッドを介して読み取る必要があります。

このメソッドはURLオブジェクトを返します。InputStream

于 2012-07-26T19:33:16.843 に答える