我当前的应用程序需要从文件中获取数据以初始化其属性。它需要存储在一个文件中才能对用户进行修改。
String strFile = ClassLoader.getSystemResource("myFile.csv").getPath();
if(strFile==null)
throw new Exception("File not find");
BufferedReader br = new BufferedReader(new FileReader(strFile));
//Begin reading file process..
我的问题是它strFile
不为空,但在初始化时我有一个java.io.FileNotFoundExceptionbr
,请参见以下堆栈:
java.io.FileNotFoundException: C:\Users\TH951S\My%20Documents\Eclipse\Workspace
\My%20App\bin\myFile.csv
(The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
我检查了文件是否在指定的路径中,并且一切似乎都正确。
有谁知道为什么会这样?或者当路径未知时,还有另一种获取文件的方法吗?
感谢阅读和更多的回答,