-1
我想读.TXT文件到Eclipse控制台,但我似乎无法弄清楚的问题是什么,我都会得到一个FileNotFoundException
时,我想阅读它 - 这是我到目前为止的代码:FileNotFoundException异常爪哇 - 无法找到TXT文件
public static void main(String[] args) throws IOException{
Map<String,String> map = new HashMap<String, String>();
BufferedReader in;
in = new BufferedReader(new FileReader("./morse-code.txt"));
String line = "";
while ((line = in.readLine()) != null){
String parts[] = line.split("\t");
map.put(parts[0], parts[1]);
}
in.close();
System.out.println(map.toString());
}
该文件是在正确的目录,我检查如果IDE在正确的道路与搜索:
String curDir = System.getProperty("user.dir");
System.out.println("Current sys dir: " + curDir);
但尽管如此,如果我想从文件中读取我收到此错误:
Exception in thread "main" java.io.FileNotFoundException: C:\Users\User\workspace\AuD\morse-code.txt (Das System kann die angegebene Datei nicht finden)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at orkgrunzer.OrkGrunzer.main(OrkGrunzer.java:16)
我不能发现问题,也许有人可以帮助我:)
抱任何包中定义的? –
如果在命令提示符中执行'notepad C:\ Users \ User \ workspace \ AuD \ morse-code.txt',那么该文件是否打开? –
您在此处阅读用户目录:'System.getProperty(“user.dir”);'不是当前工作目录 – Jens