【发布时间】:2012-07-05 10:04:03
【问题描述】:
我当前的应用程序需要从文件中获取数据来初始化它的属性。 它需要存储在一个文件中才能对用户进行修改。
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 不为空,但是当br 被初始化时我有一个java.io.FileNotFoundException,请参见以下堆栈:
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)
我检查了文件是否在指定的路径中,并且一切似乎都正确。
有谁知道为什么会这样?或者在路径未知的情况下有没有其他方法可以获取文件?
感谢您的阅读和更多的回答,
【问题讨论】:
标签: java bufferedreader filenotfoundexception filereader