读写指定的属性文件演示

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

代码:

import Java.io.*;

import java.util.Properties;

public class PropertiesDemo {

public static void main(String[] args)

{

String pFilename = System.getProperty("user.dir")

+ System.getProperty("file.separator") + "test.properties"; // 构造文件名

Properties p = new Properties();

try

{

FileInputStream in = new FileInputStream(pFilename); // 构造文件的输入流

p.load(in); // 读入属性

in.close();

}

catch(Exception e)

{

System.out.println("Error of create input stream");

}

System.out.println(p.getProperty("property1"));

p.setProperty("property1","new value"); // 给property1赋新的值

try

{

FileOutputStream out = new FileOutputStream(pFilename);

p.store(out,"This file is a test"); // 设置属性文件的文件头信息

out.flush();

out.close();

}

catch(Exception e)

{

System.out.println("Error of write input stream");

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航