System的操作类

xiaoxiao2021-02-27  658

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")); } }
转载请注明原文地址: https://www.6miu.com/read-667.html

最新回复(0)