// 打包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));
//
// }
java相对路径与properties文件读取
最新推荐文章于 2024-09-28 16:35:05 发布