Properties和IO流集合的方法
方法名 | 说明 |
void load(InputStream inStream) | 从输入字节流读取属性列表(键和元素) |
void load(Reader reader) | 从输入字符流读取属性列表(键和元素对) |
void store(OutputStream out,String comments) | 将此属性列表(键和元素对)写入此Properties表中,以适合于使用load(InputStream)方法的格式写入输出字符流 |
void store(Writer writer,String comments) | 将此属性列表(键和元素对)写入此Properties表中,以适合使用load(Reader)方法的格式写入输出字符流 |
package com.aynu13;//void load(InputStream inStream) 从输入字节流读取属性列表(键和元素)
// void load(Reader reader) 从输入字符流读取属性列表(键和元素对)
// void store(OutputStream out,String comments) 将此属性列表(键和元素对)写入此Properties表中,以适合于使用load(InputStream)方法的格式写入输出字符流
// void store(Writer writer,String comments) 将此属性列表(键和元素对)写入此Properties表中,以适合使用load(Reader)方法的格式写入输出字符流import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;public class PropertiesDemo2 {public static void main(String[] args) throws IOException {//把集合中的数据保存到文件
// myStore();//把文件中的数据加载到集合myLoad();}private static void myLoad() throws IOException{Properties prop=new Properties();//void load(Reader reader)FileReader fr=new FileReader("D:\\\\idea1\\\\workplace\\\\myMap\\\\fw.txt");prop.load(fr);fr.close();System.out.println(prop);}private static void myStore() throws IOException {//创建集合对象Properties prop=new Properties();prop.setProperty("aynu001","塞拉斯");prop.setProperty("aynu002","雷克塞");prop.setProperty("aynu003","加里奥");//void store(Writer writer,String comments)FileWriter fw=new FileWriter("D:\\\\idea1\\\\workplace\\\\myMap\\\\fw.txt");prop.store(fw,null);fw.close();}
}