store有两个成员方法
void store(OutputStream out , String comments)
void store(Writer writer,String comments)
参数:
OutputStream out :字节流输出,不能写中文
Writer writer : 字符流输出,可以写中文
String comments:注释,用来解释说明保存的文件是做什么用的,不能使用中文,会产生乱码。默认是unicode编码,一般使用""空字符串
package xuexi.heima.Properties;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Properties;
public class Demo02 {
public static void main(String[] args) throws IOException {
show01();
show02();
}
private static void show02() throws IOException {
Properties prop = new Properties();
prop.setProperty("haha","123");
prop.setProperty("haha1","234");
prop.setProperty("haha2","334");
prop.setProperty("哈哈","三三四");
FileOutputStream fos = new FileOutputStream("D:\\javadome\\javaxuexi\\src\\xuexi\\heima\\Properties\\2.txt");
prop.store(fos,"zhushi1");
fos.close();
}
private static void show01() throws IOException {
Properties prop = new Properties();
prop.setProperty("haha","123");
prop.setProperty("haha1","234");
prop.setProperty("haha2","334");
prop.setProperty("哈哈","三三四");
FileWriter fw = new FileWriter("D:\\javadome\\javaxuexi\\src\\xuexi\\heima\\Properties\\1.txt");
prop.store(fw,"zhushi");
fw.close();
}
}
分享到: