第九天,System类获取系统环境变量和系统参数
来源:互联网 发布:广东省软件协会 编辑:程序博客网 时间:2024/06/03 19:52
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
- 第九天,System类获取系统环境变量和系统参数
- System.getProperties()获取系统环境变量
- Java的System.getProperty()方法可以获取系统变量和System.getenv()获取系统环境变量
- 第九天 修改绘图系统
- 第九天 企业进销存系统
- 通过System.getProperties()获取系统参数
- java 通过System.getProperties()获取系统参数
- java 通过System.getProperties()获取系统参数
- java 通过System.getProperties()获取系统参数
- java 通过System.getProperties()获取系统参数
- Java通过System.getProperties()获取系统参数
- 通过System.getProperties()获取系统参数
- 通过System.getProperties()获取系统参数
- 通过System.getProperties()获取系统参数
- java 通过System.getProperties()获取系统参数
- Java 通过System.getProperties()获取系统参数
- java 通过System.getProperties()获取系统参数
- 通过System.getProperties()获取系统参数
- TCP的拥塞控制
- 软件安装
- getElementsByClassName兼容IE低版本
- TCP滑动窗口与回退N针协议
- 使用Gradle编译执行Gague项目
- 第九天,System类获取系统环境变量和系统参数
- Http的报文结构
- live555学习笔记11-h264 RTP传输详解(3)
- windows下安装keras
- Spring Mvc上传文件
- Http1.1和Http1.0的区别
- String、StringBuffer、StringBuilder区别
- Java并发编程:线程池的使用
- JavaScript中"=="