java相对路径与properties文件读取
程序员文章站
2022-05-10 09:10:48
...
// 打包jar同目录下的application.properties,未打包 bin/application.properties
File file = new File(path + "application.properties");
Properties properties = new Properties();
InputStream in = new BufferedInputStream(new FileInputStream(file));
properties.load(in);
int port = Integer.parseInt(properties.getProperty("server.port"));
// 遍历properties
// Iterator<String> it = properties.stringPropertyNames().iterator();
// while(it.hasNext()) {
// String key = it.next();
// System.out.println(key+":" + properties.getProperty(key));
//
// }