2011-02-22 144 views
1

我是Java的新手。我使用Eclipse IDE。我有這樣的軟件包結構:資源文件無法找到

Java src: 
     -1)org.pdfbox; 
     -2)org.pdfbox.util; 
     -3)org.pdfbox.pdmodel.interactive.documentnavigation.outline 
     - ..... 
     -4)org.pdfbox.util; 
         -4.1)ResourceLoader.java - loads data from .properties file ; 
         -4.2)..... 
         -4.3)..... 
     -5)org.pdfbox.Resources; 
         -5.1)files to be downloaded (*.properties). 

包含資源有灰色圖標,其他包有棕色圖標。當我嘗試從org.pdfbox.Resources中加載文件時,ResourceLoader會拋出一個異常「文件無法找到」。有沒有辦法將包含屬性的包納入項目或其他東西?我試圖設置絕對或相對路徑到我的屬性文件。對你的幫助非常有幫助。

+0

向我們展示用於加載性能的代碼,以及異常的堆棧跟蹤。 – 2011-02-22 21:49:41

回答

2

如果你的屬性文件名爲myfile.properties,那麼你的代碼應該是這樣的: -

ResourceBundle rb = ResourceBundle.getBundle("org.pdfbox.Resources.myfile"); 

// get the string value from key "myvar" from the properties file 
String s = rb.getString("myvar"); 
+1

謝謝。它幫助了我。 – Marina 2011-02-23 18:59:38