2011-10-29 56 views
1

我正在處理Web應用程序,並且我在包com.xx.yy中創建了一個屬性文件。我需要從作者包com.aa.bb中的類中讀取此文件。我在使用FileInputStream讀取屬性文件時遇到問題

我有如下因素代碼:

try { 
    FileInputStream fileInputStream = new FileInputStream("com/xx/yy/myfile.properties"); 
    internationalizationFile = new Properties(); 
    internationalizationFile.load(fileInputStream); 
    fileInputStream.close(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

,但它不工作!

+1

你會得到什麼?例外? –

回答

2

您是否嘗試通過類加載器加載資源?像:

InputStream in = this.getClass().getClassLoader.getResourceAsStream("com/xx/yy/myfile.properties"); 
相關問題