2016-02-22 112 views
0

我的代碼無法讀取屬性文件。任何人都可以幫忙嗎?它打印無法找到該文件。閱讀Java中的屬性文件

BufferedReader br = null; 
String strLine = ""; 
try { 
    br = new BufferedReader(new FileReader("C:/common-test/common-test/translationtest/messages_ja.property")); 
    while((strLine = br.readLine()) != null){ 
     System.out.println(strLine); 
    } 
} catch (FileNotFoundException e) { 
    System.err.println("Unable to find the file: fileName"); 
} catch (IOException e) { 
    System.err.println("Unable to read the file: fileName"); 
} 
+0

更改'/'到'\\',也逃脫他們 – Ramanlfc

+1

我強烈建議打印實際的異常,而不是自己的自定義輸出。這會給你更多的信息(比如爲什麼它不工作)。 – Hypino

+1

你會得到什麼例外?請使用此代碼'catch(IOException e){e.printStackTrace(); }'並向我們顯示錯誤消息 – Nayuki

回答

0

嘗試使用此\\

"C:\\common-test\\common-test\\translationtest\\messages_ja.property" 

你一定要使用.property.properties