首页 > 学院 > 开发设计 > 正文

第九天,System类获取系统环境变量和系统参数

2019-11-08 18:27:02
字体:
来源:转载
供稿:网友
import java.util.Enumeration;import java.util.Iterator;import java.util.Map;import java.util.Map.Entry;import java.util.PRoperties;import java.util.Set;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Collection;import java.io.FileOutputStream;/** * Description: * System类的一些方法的使用 * * @author Lee * */public class Demo { /** * Description; * 获取系统的环境变量 * */ public static void test1(){ /* public static Map<String,String> getenve() Returns an unmodfiable string map view of the current system environment. public static String getenv(String name) Gets the value of the specified environment variable. */ //获取系统地环境变量的Map集合 Map<String,String> map = System.getenv(); //第一种方法迭代Map的方法,获取键的Set集合 Set<String> keySet = map.keySet(); for(Iterator interator=keySet.iterator();interator.hasNext();){ String key = (String)interator.next(); System.out.println(key+" = "+map.get(key)); } System.out.println("----------------------------------------------"); //第二种迭代Map的方法,获取value的Collection集合 Collection<String> values = map.values(); for(Iterator iterator = values.iterator();iterator.hasNext();){ String value = (String)iterator.next(); System.out.println(value); } System.out.println("----------------------------------------------"); //第三种迭代Map的方法,获取键-值得Map.Entry集合 Set<Entry<String,String>> entrySet = map.entrySet(); for(Iterator iterator = entrySet.iterator();iterator.hasNext();){ Entry<String,String> entry = (Entry<String,String>)iterator.next(); System.out.println(entry.getKey()+" = "+entry.getValue()); } /* public static Properties getProperties() ->Dtermines the current system properties public static String getProperties(String key) ->Gets the system property indicated by the specified key. public static String getProperties(String key,String default); Returns:the string value of the system property, or the default value if there is no property with that key. */ //获取系统参数 Properties ps = System.getProperties(); //System.out.println(System.getProperties()); //System.getProperty("sdfsd"); //System.getProperty("dfsdf","default"); /* An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series. */ Enumeration enumeration = ps.propertyNames(); while(enumeration.hasMoreElements()){ String str = (String)enumeration.nextElement(); System.out.println(str+" = "+ps.getProperty(str)); } } public static void main(String[] args) { }}

附记: 系统参数:

Key Description of Associated Value java.version —->Java Runtime Environment version java.vendor —->Java Runtime Environment vendor java.vendor.url—->Java vendor URL java.home—->Java installation directory java.vm.specification.version—->Java Virtual Machine specification version java.vm.specification.vendo—->Java Virtual Machine specification vendor java.vm.specification.name Java Virtual Machine specification name java.vm.version—->Java Virtual Machine implementation version java.vm.vendor—->Java Virtual Machine implementation vendor java.vm.name—->Java Virtual Machine implementation name java.specification.version—->Java Runtime Environment specification version java.specification.vendor—->Java Runtime Environment specification vendor java.specification.name—->Java Runtime Environment specification name java.class.version—->Java class format version number java.class.path—->Java class path java.library.path—->List of paths to search when loading libraries java.io.tmpdir—->Default temp file path java.compiler—->Name of JIT compiler to use java.ext.dirs—->Path of extension directory or directories Deprecated. This property, and the mechanism which implements it, may be removed in a future release. os.name—->Operating system name os.arch Operating—->system architecture os.version—->Operating system version file.separator—->File separator (“/” on UNIX) path.separator—->Path separator (“:” on UNIX) line.separator—->Line separator (“/n” on UNIX) user.name—->User’s account name user.home—->User’s home directory user.dir—->User’s current working directory


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表