322 Properties和IO流相组合的方法
(myOtherStream)
【Properties和IO流相组合的方法】
1 | void load(InputStream InStream) | 从 输入字节流 读取属性列表(键和元素对) |
2 | void load(Reader reader) | 从 输入字符流 读取属性列表(键和元素对) |
3 | void store(OutputStream out,String comments) | 将 此属性列表(键和元素对)写入此Properties表中,以 适于使用load(InputStream)方法的格式 写入 输出字节流 |
4 | void store(Writer writer,String comments) | 将 此属性列表(键和元素对)写入此Properties表中,以 适于使用load(InputStream)方法的格式 写入 输出字符流 |
---------------------------------------------
package e320;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
public class PropertiesDemo322 {
public static void main(String[] args) throws IOException {
// myStore();
myLoad();
}
private static void myLoad() throws IOException {
Properties prop = new Properties();
FileReader fr = new FileReader("myOtherStream\\src\\e320\\22.txt");
prop.load(fr);
fr.close();
System.out.println(prop);
}
private static void myStore() throws IOException {
Properties prop = new Properties();
prop.setProperty("s322", "MOLE");
prop.setProperty("s323", "RABBIT");
prop.setProperty("s324", "RAT");
FileWriter fw = new FileWriter("myOtherStream\\src\\e320\\22.txt");
prop.store(fw, null);
fw.close();
}
}
//{s323=RABBIT, s322=MOLE, s324=RAT}
---------------------------------------------
(22.txt)
#Tue Oct 12 09:57:58 CST 2021
s323=RABBIT
s322=MOLE
s324=RAT