java Properties结合IO流使用,配置文件
1、创建 xx.properties文件
2、创建 FileInputStream对象
3、创建Properties对象
4、properties加载FileinputStream对象
5、遍历文件数据
6、案例
package com.wt.buffer; import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; import java.util.Set; public class Demon06 { public static void main(String[] args) { // 1.打开文件 try( FileInputStream fileInputStream = new FileInputStream("module3\\tests.properties");) { Properties properties = new Properties(); // 2.加载 properties.load(fileInputStream); // 3.遍历 Set<String> strings = properties.stringPropertyNames(); for (String string : strings) { System.out.println(string+"..."+properties.getProperty(string)); } } catch (IOException e) { throw new RuntimeException(e); } } }