当前位置: 技术问答>java相关
Properties文件的读写
来源: 互联网 发布时间:2015-10-19
本文导语: import java.io.*; import java.util.Properties; public class Test { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("Test.properties"); Properties prop = new Properties(); prop.load(fis); System.out.println(prop.getProperty("a")...
import java.io.*;
import java.util.Properties;
public class Test
{
public static void main(String[] args)
{
try
{
FileInputStream fis = new FileInputStream("Test.properties");
Properties prop = new Properties();
prop.load(fis);
System.out.println(prop.getProperty("a"));
System.out.println(prop.getProperty("b"));
prop.setProperty("b","this");
System.out.println(prop.getProperty("b"));
prop.clear();
fis.close();
}
catch(IOException e) {}
}
}
显示100,200,this可是
Test.properties的文件内容依然是
a=100
b=200
运行后应该是b=this啊?怎么回事?
import java.util.Properties;
public class Test
{
public static void main(String[] args)
{
try
{
FileInputStream fis = new FileInputStream("Test.properties");
Properties prop = new Properties();
prop.load(fis);
System.out.println(prop.getProperty("a"));
System.out.println(prop.getProperty("b"));
prop.setProperty("b","this");
System.out.println(prop.getProperty("b"));
prop.clear();
fis.close();
}
catch(IOException e) {}
}
}
显示100,200,this可是
Test.properties的文件内容依然是
a=100
b=200
运行后应该是b=this啊?怎么回事?
|
FileOutputStream fos = new FileOutputStream("Test.properties");
prop.store(fos,"");
fos.close();
prop.store(fos,"");
fos.close();