代码如下:
package PropertiesPack;import java.util.Properties;
import java.util.Set;public class PropertiesDemo01 {public static void main(String[] args){Properties prop = new Properties();prop.put("001","Tom");prop.put("002","Jack");prop.put("003","Lily");Set<Object> keySet = prop.keySet();for (Object key:keySet){Object value = prop.get(key);System.out.println(key+","+value);}}}
代码如下:
package PropertiesPack;import java.util.Properties;
import java.util.Set;public class PropertiesDemo02 {public static void main(String[] args){Properties prop = new Properties();prop.setProperty("001","Tom");prop.setProperty("002","Jack");prop.setProperty("003","Lily");System.out.println(prop.getProperty("001"));System.out.println(prop.getProperty("002"));System.out.println(prop.getProperty("004"));Set<String> names = prop.stringPropertyNames();for (String key:names){String value = prop.getProperty(key);System.out.println(key+","+value);System.out.println(key);}System.out.println(prop);}
}
代码如下:
package PropertiesPack;import java.io.*;
import java.util.Properties;public class PropertiesDemo03 {public static void main(String[] args) throws IOException {myStore();myLoad();}private static void myLoad() throws IOException {Properties prop = new Properties();FileReader fr = new FileReader("D:\\JavaDemo\\fw.txt");prop.load(fr);fr.close();System.out.println(prop);}private static void myStore() throws IOException {Properties prop = new Properties();prop.setProperty("001","Tom");prop.setProperty("002","Jack");prop.setProperty("003","Lily");FileWriter fw = new FileWriter("D:\\JavaDemo\\fw.txt");prop.store(fw,null);fw.close();}}