`
哈达f
  • 浏览: 114966 次
  • 性别: Icon_minigender_1
  • 来自: 广西
社区版块
存档分类
最新评论

Properties用法

    博客分类:
  • j2se
 
阅读更多
import java.io.*;
import java.util.*;

class  PropertiesDemo
{
	public static void main(String[] args) throws IOException
	{

//		Properties prop = System.getProperties();//new Properties();

//		prop.setProperty("01","zhangsan");
//		prop.setProperty("02","lisi");



//		prop.list(new PrintStream("sys.txt"));


		


//		infoToProp();

		Properties prop = new Properties();

		FileInputStream fis = new FileInputStream("info.txt");

		prop.load(fis);
		
		prop.setProperty("lisi","29");

		FileOutputStream fos = new FileOutputStream("info.txt");

		prop.store(fos,"hahha");

//		System.out.println(prop.getProperty("wangwu"));

		fos.close();
		fis.close();

	}

	public static void infoToProp()throws IOException
	{
		Properties prop = new Properties();

		BufferedReader bufr = 
			new BufferedReader(new FileReader("info.txt"));

		String line = null;

		while((line=bufr.readLine())!=null)
		{
//			System.out.println(line);
			String[] arr = line.split("=");
			prop.setProperty(arr[0],arr[1]);
		}


		System.out.println(prop.getProperty("lisi"));
		bufr.close();
	}
}


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics