我是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).
Package with Resources有灰色图标,其他包有棕色图标。当我尝试从org.pdfbox.Resources加载文件时,ResourceLoader抛出异常“无法找到文件”。有没有办法将包含属性的包包含在项目中?我试图设置ab属性文件的绝对路径或相对路径。非常感谢你的帮助。
答案 0 :(得分: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");