-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