package IO.file.test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Properties;
import java.util.Set;
public class PropertiesDemo {
public static void main(String[] args) throws IOException {
method_4();
}
private static void method_4() throws IOException {
Properties pro = new Properties();
BufferedReader bufr=new BufferedReader(new FileReader("a.txt"));
String line=null;
while((line=bufr.readLine())!=null)
{
if(line.startsWith("#"))
continue;
String[] arr=line.split("=");
// System.out.println(arr[0]+" "+arr[1]);
pro.setProperty(arr[0], arr[1]);
}
pro.list(System.out);
bufr.close();
}
public static void method_3() throws IOException {
Properties pro = new Properties();
FileInputStream fis=new FileInputStream("a.txt");
pro.load(fis);
pro.list(System.out);
}
static void method_2() throws IOException
{
Properties pro = new Properties();
pro.setProperty("zhangsan", "30");
pro.setProperty("lisi", "32");
pro.setProperty("maer", "34");
pro.setProperty("mazi", "45");
pro.setProperty("wangwu", "12");
pro.store(new FileWriter("a.txt"), "name+age");
//pro.store(new FileOutputStream("a.txt"), "name+age");
}
public static void method_1()
{
Properties pro = new Properties();
pro.setProperty("zhangsan", "30");
pro.setProperty("lisi", "32");
pro.setProperty("maer", "34");
pro.setProperty("mazi", "45");
pro.setProperty("wangwu", "12");
pro.list(System.out);
System.out.println();
pro = System.getProperties();
System.out.println(pro);
// 修改值
/*
* pro.setProperty("mazi", "22"); Set<String>
* names=pro.stringPropertyNames(); for(String name:names){ String
* value=pro.getProperty(name); System.out.println(name); }
*/
}
}