store(OutputStream out, String comments) 将此 Properties表中的此属性列表(键和元素对)以适合于使用 load(InputStream)方法加载到 Properties表格的格式写入输出流。
FileOutputStream fos=new FileOutputStream(new File("E:\\java\\itcast\\properties.txt"));
Properties properties =new Properties();
properties.setProperty("01","小王");
properties.setProperty("02","小李");
properties.setProperty("03","小张");
properties.store(fos,null);
fos.close();
store(Writer writer, String comments) 将此属性列表(键和元素对)写入此 Properties表中,以适合使用 load(Reader)方法的格式输出到输出字符流。
private static void mystore() throws IOException {
FileWriter fw=new FileWriter("E:\\java\\myotherstream.txt");
Properties pp=new Properties();
pp.setProperty("01","小赵");
pp.setProperty("02","小钱");
pp.setProperty("03","小李");
pp.store(fw,null);
fw.close();
load(InputStream inStream) 从输入字节流读取属性列表(键和元素对)。
FileInputStream fis=new FileInputStream("E:\\java\\myotherstream2.txt");
Properties pp=new Properties();
pp.load(fis);
System.out.println(pp);
fis.close();
//load(Reader reader) 以简单的线性格式从输入字符流读取属性列表(关键字和元素对)。
//字符流
private static void myload() throws IOException {
FileReader fr=new FileReader("E:\\java\\myotherstream.txt");
Properties pp=new Properties();
pp.load(fr);
System.out.println(pp);
fr.close();
}