System的操作类

来源:互联网 发布:淘宝虚假交易要清洗吗 编辑:程序博客网 时间:2024/06/14 01:00
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;

public class SystemDemo {

public static void main(String[] args) throws FileNotFoundException, IOException {


// 获取系统的所有环境变量
Map<String, String> getenv = System.getenv();
// 实现对集合的遍历
for (String name : getenv.keySet()) {
System.out.println(name + "===" + getenv.get(name));
}


// 获取指定变量的值
System.out.println("JAVA_HOME环境变量的值为:" + System.getenv("JAVA_HOME"));
// 获取系统的所有属性
Properties properties = System.getProperties();
// 将所有的系统属性保存到d盘的test.txt中
properties.store(new FileOutputStream(new File("d:" + File.separator + "test.txt")), "System.getProperties");
// 输出特定的系统属性
System.out.println("操作系统是"+System.getProperty("os.name"));
}
}
0 0