欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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));
//				
//			}			

参考 Java 读写Properties配置文件