Properties中的load方法以及缓冲流的原理
Properties中的load方法
可以使用Properties集合中的方法load,把硬盘中保存的文件(键值对),读取到集合中使用
void load(InputStream inStream)
void load(Reader reader)
参数:
InputStream inStream):字节输入流,不能读取含有中文的键值对
Reader reader:字符输入流,能读取含有中文的键值队
使用步骤:
1.创建Properties集合对象
2.使用Properties集合对象中的方法load读取保存键值对的文件
3.遍历Properties集合
注意:
1.存储键值对的文件中,键与值默认的连接符号可以使用=,空格(其他符号)
2.存储键值对的文件中,可以使用#进行注释,被注释的键值对不会再被读取
3.存储键值对的文件中,键与值默认都是字符串,不用再加引号
public static void main(String[] args) throws IOException { //创建Properties结婚 Properties properties = new Properties();//使用properties集合对象中的方法load读取保存键值的文件 properties.load(new FileReader("E:\\a.txt")); //遍历properties集合 Set<String> set = properties.stringPropertyNames(); for (String s : set) { String property = properties.getProperty(s); System.out.println(s+"="+property); } }
运行结果:

缓冲流的原理
缓冲流也称为处理流,对文件或者其他目标频繁的操作,效率低,性能差。
缓冲流目的是提高程序读取和写出的性能。
缓冲流也分为字节缓冲流(如FileInputStream与FileOutputStream)和字符缓冲流(如FileReader与FileWriter)


浙公网安备 33010602011771号