(88)将系统属性输出到文件中Properties.list方法
import java.util.*;
import java.io.*;
public class SystemInfor {
public static void main(String[] args) {
Properties prop=System.getProperties();//在Java(81)中因为Properties中都是键值对,所以通过迭代器对其遍历过
//System.out.println(prop);
//prop.list(System.out);//System.out.println(prop);中并没有换行,不利于查看,在list方法中是将属性列表输出到指定的输出流中,在此处是打印到控制台中
try {
PrintStream ps=new PrintStream("Properties.txt");//涉及到文件操作,就得有异常处理
System.setOut(ps);
prop.list(ps);//在此处是打印到文件中
}catch(IOException e) {
throw new RuntimeException("属性文件创建失败");
}
}
}