读取本机的Java运行环境和相关配置文件的内容
2009-09-10 00:00:00 来源:WEB开发网import java.util.*;
import java.io.*;
class TestProperty
{
public static void main(String[] args)
{
Properties psys=System.getProperties();
String path = psys.getProperty("user.dir");//程序所在的路径;
// psys.list(System.out);
//写文件
try
{
File f = new File(path+"\\config\\test.txt");
FileWriter fw = new FileWriter(f);
PrintWriter pw = new PrintWriter(fw);
Enumeration em= psys.propertyNames();
while(em.hasMoreElements())
{
String strKey=(String)em.nextElement();
String strValue = psys.getProperty(strKey);
pw.println(strKey+"="+strValue);
}
fw.close();
//读文件
File f1 = new File(path+"\\config\\test.txt");
FileReader fr = new FileReader(f1);
BufferedReader br= new BufferedReader(fr);
String content ="";
String str ="";
while((content=br.readLine())!=null)
{
str += content+"\r\n";
}
System.out.println(str);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
更多精彩
赞助商链接