与XML一样都是配置文件,一般简单的,没有结构的用properties,复杂的,有结构的用XML就行了:
读操作:
[code]
File f = new File("abc.properties");//这个也可以改成.ini的文件
FileInputStream fin = new FileInputStream(f);
Properties proc = new Properties();
proc.load(fin);
String s = proc.getProperty("name");
System.out.println(s);//可以得到123
fin.close();
[/code]
abc.properties文件:
一般都是用键值对来表示
[code]
#Fri May 18 16:22:07 CST 2007
name=123
[/code]
写操作:
[code]
File f = new File("abc.properties");
FileInputStream fin = new FileInputStream(f);
FileOutputStream out = new FileOutputStream(f);
Properties proc = new Properties();
proc.load(fin);
proc.setProperty("name", "123");
proc.store(out,"This is comment");
out.close();
fin.close();
[/code]
abc.properties文件:
[code]
#This is comment
#Fri May 18 16:28:37 CST 2007
name=123
[/code]
读操作:
[code]
File f = new File("abc.properties");//这个也可以改成.ini的文件
FileInputStream fin = new FileInputStream(f);
Properties proc = new Properties();
proc.load(fin);
String s = proc.getProperty("name");
System.out.println(s);//可以得到123
fin.close();
[/code]
abc.properties文件:
一般都是用键值对来表示
[code]
#Fri May 18 16:22:07 CST 2007
name=123
[/code]
写操作:
[code]
File f = new File("abc.properties");
FileInputStream fin = new FileInputStream(f);
FileOutputStream out = new FileOutputStream(f);
Properties proc = new Properties();
proc.load(fin);
proc.setProperty("name", "123");
proc.store(out,"This is comment");
out.close();
fin.close();
[/code]
abc.properties文件:
[code]
#This is comment
#Fri May 18 16:28:37 CST 2007
name=123
[/code]