pro.properties文件
1 aa=1 2 bb=2
1 package demo05; 2 3 import java.io.FileReader; 4 import java.io.FileWriter; 5 import java.io.IOException; 6 import java.util.Properties; 7 8 public class PropertiesDemo { 9 public static void main(String[] args) throws IOException { 10 Properties p = new Properties(); 11 p.setProperty("a", "1"); 12 p.setProperty("b", "2"); 13 System.out.println(p); 14 15 String value = p.getProperty("a"); 16 System.out.println(value); 17 18 Properties p1 = new Properties(); 19 FileReader fr = new FileReader("c:\\pro.properties"); 20 p1.load(fr); 21 fr.close(); 22 System.out.println(p1); 23 24 Properties p2 = new Properties(); 25 p2.setProperty("aa", "1"); 26 p2.setProperty("bb", "2"); 27 FileWriter fw = new FileWriter("c:\\pro.properties"); 28 p2.store(fw, ""); 29 fw.close(); 30 } 31 }
时间: 2024-10-16 20:33:36