【发布时间】:2011-10-05 12:16:21
【问题描述】:
我有一个位于默认包内的属性文件,并且我使用该属性文件的类也在同一个默认包中。如果我只使用没有任何路径的文件名,我会收到错误消息。显然这是不正确的,因为我应该给出某种路径来引用 tat 文件。我将构建应用程序使其成为一个 jar 文件,所以我应该如何给出路径,因为属性文件应该进入该 jar 文件。我正在使用 Netbeans IDE。
编辑
Properties pro = new Properties();
try {
pro.load(new FileInputStream("pos_config.properties"));
pro.setProperty("pos_id", "2");
pro.setProperty("shop_type", "2");
pro.store(new FileOutputStream("pos_config.properties"), null);
String pos_id = pro.getProperty("pos_id");
if(pos_id.equals("")){
pos_id="0" ;
}
global_variables.station_id = Integer.parseInt(pos_id);
String shop_type = pro.getProperty("shop_type");
if(shop_type.equals("")){
shop_type="0" ;
}
global_variables.shop_type = Integer.parseInt(shop_type);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
【问题讨论】:
-
请发布您用于访问属性文件的代码。
-
@little bunny foo foo:检查我的编辑..
-
我不使用netbeans,但如果你在netbeans中点击右键文件,你不会有类似
build path > include -
代码审查评论:看起来您的代码和该问题答案中的大多数代码示例都无法关闭输入流。这可能会给您带来麻烦。
标签: java resources properties jar