java打包后的jar文件访问properties文件
在打包成jar文件时,不要讲properties文件及其目录打包进jar,要放到jar外面。
访问properties的代码:
public DBHelp(){
Properties properties = new Properties();
try {
URI uri = Paths.get("resource/dblook.properties").toAbsolutePath().toUri();
System.out.println(uri);
File file = new File(uri);
properties.load(new java.io.FileInputStream(file));
} catch (FileNotFoundException ex) {
Logger.getLogger(DBHelp.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DBHelp.class.getName()).log(Level.SEVERE, null, ex);
}
阅读(1863) | 评论(0) | 转发(0) |