开发者

File location for reading the file

开发者 https://www.devze.com 2023-02-28 15:50 出处:网络
I need to set a file location in a properties file to use it later in the class file. for example I have,

I need to set a file location in a properties file to use it later in the class file. for example I have,

anamelistfile = /rsrs/anamelist.txt

This is set up in file propss.properties in the folder config directly under the context. same with "rsrs" folder.

In my class file I need to get this file location. I used follwing code to get it and I got the required value in fileloc object.

fileloc=Props.getproperty(anamelistfile )
//result was fileloc="/rsrs/anamelist.txt"

I used following code to read the file. But once the File object is created, it is treating the file path as "\rsrs\anamelist.txt" and I am getting a file not found exception.

File listFile = new File(fileloc);
BufferedReader input = new BufferedReader(new FileReader(listFile));

error message Exception: Stack Trace for:java.io.FileNotFoundException: \rsrs\anamelist.txt (The system cannot find the path specified)

Can someone please help me with what mistake I am making here? Also my dev environment is windows and prod is on Unix, so I need the solution to work on both. 开发者_Go百科Thanks in advance


Try...

InputStream fIn = Thread.currentThread().getContextClassLoader().getResourceAsStream("/rsrs/anamelist.txt");
BufferedReader input = new BufferedReader(new InputStreamReader(fIn));
0

精彩评论

暂无评论...
验证码 换一张
取 消