---------------------- android培训、 java培训、期待与您交流! ----------------------
Properties 是hashtable的子类。就是说它具备map集合的特点,可以存储字符串的键值对。
是集合中和IO技术相结合的集合容器。
该对象的特点:可以用于键值对形式的配置文件。那么在加载数据时,需要有固定格式:键=值。
import java.io.*;
import java.util.*;
class PropertiesDemo
{
public static void main(String[] args) throws IOException
{
loadDemo();
}
public static void loadDemo()throws IOException
{
Properties prop = new Properties();
FileReader fr = new FileReader("info.txt");
prop.load(fr);
prop.setProperty("lisi","22");
FileWriter fw = new FileWriter("info.txt");
prop.store(fw,"change");
prop.list(System.out);
fr.close();
fw.close();
}
public static void method()throws IOException
{
BufferedReader bufr = new BufferedReader(new FileReader("info.txt"));
String len = null;
Properties prop = new Properties();
while((len = bufr.readLine())!=null)
{
String[] str = len.split("=");
prop.setProperty(str[0],str[1]);
}
sop(prop);
bufr.close();
}
public static void setAndGet()
{
Properties prop = new Properties();
prop.setProperty("zhangsan","30");
prop.setProperty("lisi","35");
sop(prop);
String value = prop.getProperty("lisi");
sop(value);
Set<String> names = prop.stringPropertyNames();
for(String s : names)
{
sop(s+":"+prop.getProperty(s));
}
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
----------------------- android培训、 java培训、期待与您交流! ----------------------详细请查看: http://edu.csdn.net/heima