|
在h盘根目录下建一个空myproper.txt文件(ansi编码)
import java.io.* ;
import java.util.* ;
public class PropertyFileTest {
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
properties.load(new FileInputStream(new File("H:\\myproper.txt")));
String property = properties.getProperty("name", "张三");
System.out.println(property);
properties.put("name","雷峰");
properties.store(new FileOutputStream("H:\\myproper.txt"),"Properties test");
}
}
程序运行显示:
张三
然后再打开myproper.txt文件内容如下:
#Properties test
#Tue Aug 17 21:29:31 CST 2021
name=\u96F7\u5CF0
|
|