1.System.getProperty(String name)方法用于得到系统的属性.System是在lang包中的一个类,这个类中存在大量和系统打交道的实用方法,而且一般都是类方法,.getProperty(String key)就是其中一个比较常用的方法,用于返回系统参数文件中这个方法指定键所代表的值。
下面是该方法的常用参数。关键意义
-------------------------------------------------
java.versionjava.version Java运行环境版本
java.vendorjava.vendor Java运行环境卖主
java.vendor.urljava.vendor.url Java卖主的URL
java.homejava.home Java的安装目录
java.vm.specification.version Java虚拟机规范版本
java.vm.specification.vendor Java虚拟机规范供应商
java.vm.specification.name Java虚拟机规范名称
java.vm.versionjava.vm.version Java虚拟机执行版本
java.vm.vendorjava.vm.vendor Java虚拟机实现供应商
java.vm.namejava.vm.name Java虚拟机实现名称
java.specification.version Java运行时环境规范版本
java.specification.vendor Java运行时环境规范供应商
java.specification.name Java运行时环境规范名称
java.class.versionjava.class.version Java类格式版本号
java.class.pathjava.class.path Java类路径
java.library.pathjava.library.path 名单上的路径搜索时,装载图书馆
java.io.tmpdirjava.io.tmpdir 默认temp文件路径
java.compilerjava.compiler 名称JIT编译器使用
java.ext.dirsjava.ext.dirs 道路扩建目录或目录
os.name 操作系统名称
os.archos.arch 操作系统体系结构
os.versionos.version 操作系统版本
file.separatorfile.separator 文件分隔符("/"在UNIX)
path.separatorpath.separator 路径分隔符(":"在UNIX)
line.separatorline.separator 线分离("\n",在Unix)
user.nameuser.name 用户的帐号名称
user.homeuser.home 用户的home目录
user.diruser.dir 用户的当前工作目录
public class SystemPropertyTest { /** * @param args */ public static void main(String[] args) { System.out.println("=================="); System.out.println("JAVA相关"); System.out.println("=================="); System.out.println("JAVA安装目录:" + System.getProperty("java.home")); System.out.println("JAVA类格式版本:" + System.getProperty("java.class.version")); System.out.println("JAVA类路径:" + System.getProperty("java.class.path")); System.out.println("JAVA加载库时搜索的路径列表:" + System.getProperty("java.library.path")); System.out.println("JAVA默认的临时文件路径:" + System.getProperty("java.io.tmpdir")); System.out.println("JAVA要使用的JIT编译器的名称:" + System.getProperty("java.compiler")); System.out.println("JAVA一个或多个扩展目录的路径:" + System.getProperty("java.ext.dirs")); System.out.println(System.getProperty("line.separator")); System.out.println("=================="); System.out.println("JAVA run time 相关"); System.out.println("=================="); System.out.println("JAVA运行时环境版本:" + System.getProperty("java.version")); System.out.println("JAVA运行时环境供应商:" + System.getProperty("java.vendor")); System.out.println("JAVA运行时环境供应商URL:" + System.getProperty("java.vendor.url")); System.out.println("JAVA运行时环境规范版本:" + System.getProperty("java.specification.version")); System.out.println("JAVA运行时环境规范供应商:" + System.getProperty("java.specification.vendor")); System.out.println("JAVA运行时环境规范名称:" + System.getProperty("java.specification.name")); System.out.println(System.getProperty("line.separator")); System.out.println("=================="); System.out.println("JVM相关"); System.out.println("=================="); System.out.println("JAVA虚拟机规范版本:" + System.getProperty("java.vm.specification.version")); System.out.println("JAVA虚拟机规范供应商:" + System.getProperty("java.vm.specification.vendor")); System.out.println("JAVA虚拟机规范名称:" + System.getProperty("java.vm.specification.name")); System.out.println("JAVA虚拟机实现版本:" + System.getProperty("java.vm.version")); System.out.println("JAVA虚拟机实现供应商:" + System.getProperty("java.vm.vendor")); System.out.println("JAVA虚拟机实现名称:" + System.getProperty("java.vm.name")); System.out.println(System.getProperty("line.separator")); System.out.println("=================="); System.out.println("操作系统相关"); System.out.println("=================="); System.out.println("操作系统名称:" + System.getProperty("os.name")); System.out.println("操作系统架构:" + System.getProperty("os.arch")); System.out.println("操作系统版本:" + System.getProperty("os.version")); System.out.println(System.getProperty("line.separator")); System.out.println("文件分隔符:" + System.getProperty("file.separator")); System.out.println("路径分隔符:这里开始" + System.getProperty("path.separator") + "这里结束"); System.out.println("行分隔符:这里开始" + System.getProperty("line.separator") + "这里结束"); System.out.println(System.getProperty("line.separator")); System.out.println("=================="); System.out.println("当前用户相关"); System.out.println("=================="); System.out.println("当前用户的账户名称:" + System.getProperty("user.name")); System.out.println("当前用户的主目录:" + System.getProperty("user.home")); System.out.println("当前用户的当前工作目录:" + System.getProperty("user.dir")); } }
2.java -D arguments 参数
-D set a system property(设置系统属性)
例如如下:
cmd 命令: java -DmyParam1=hello,world Test
public class Test{ public static void main(String[] args){ System.out.println(System.getProperty("myParam1")); // output: hello,world } }
source:http://www.iteye.com/topic/97407
http://coffeelover.iteye.com/blog/694149
相关推荐
String osName = System.getProperty("os.name"); StringBuffer systemPathBuff = new StringBuffer(""); if (osName.indexOf("Windows") > -1) ...{ // Windows操作系统的cmd.exe的绝对路径 systemPathBuff....
请注意:加入百度ueditor插件的项目或产品,在linux下部署无问题,只要部署好就可以,但是如果是windows系统的话,上传... //System.out.println("操作系统类型>>>>"+System.getProperty("os.name")); return str; }
public class HelloUser { public static void main(String[] arguments) { String username = System.getProperty("user.name"); System.out.println("Hello, " + username); } }
String NL = System.getProperty("line.separator");//为每行数据添加分隔符 while((line = in.readLine()) != null) { sb.append(line NL);//获取各行数据信息 } in.close();//关闭流 String result ...
String maxconn = props.getProperty(poolName + ".maxconn", "0"); int max; try { max = Integer.valueOf(maxconn).intValue(); } catch (NumberFormatException e) { log("错误的最大连接数限制: " + ...
System.out.println(System.getProperty("user.dir"));//输出当前的项目存放的路径 String uploadPath=req.getSession().getServletContext().getRealPath("/upload"); System.out.println(uploadPath);//输出...
_name Button._name、MovieClip._name、TextField._name _parent _parent、Button._parent、MovieClip._parent、TextField._parent _quality _quality、Button._quality、TextField._quality _root _root _...
String val = m_props.getProperty(name); if( val == null ) { return defaultVal; } else { return val; } } /** * 读取一特定的属性项 * * @param name 属性项的项名 * @return 属性...
String home = System.getProperty(Globals.CATALINA_HOME_PROP); File homeFile = null; //获取Tomcat的绝对路径 if (home != null) { File f = new File(home); try { homeFile = f.getCanonicalFile()...
接收方地址 、 内容***/ public static void send(String subject, String toaddress,String content)throws Exception { String hostName = ReadPropertity.getProperty("emailsmtp"); String fromAddress = ...
String osName = System.getProperty("os.name"); double cpuRatio = 0; if (osName.toLowerCase().startsWith("windows")) { //返回构造好的监控对象 return cpuRatio = this.getCpuRatioForWindows();...
private static final String DBINFO_FIIE_NAME = "dbinfo.properties"; private static Properties infos = new Properties(); private static String url = null; static{ InputStream is = JdbcUtil.class ...
String osName = System.getProperty("os.name").toLowerCase(); String command = ""; if (osName.startsWith("linux")) { command = "df -k " + dir; } process = run.exec(command); java.io.BufferedReader in =...
String osname = System.getProperties().getProperty("os.name"); if (osname.equals("Linux")) {//判断系统的环境win or Linux System.setProperty("phantomjs.binary.path", "/usr/bin/phantomjs"); } ...
parent = System.getProperty("user.dir"); File dir = new File(parent); // Convert it to a file. if (!dir.exists()) abort("destination directory doesn't exist: "+parent); if (dir.isFile()) abort...
一个完整示例可让你节省很多保贵的时间!花五分值!... <Itms-Config> <system> <name> 一句简单的代码就可以得到XML中name节点的值 String name = xml.getProperty("system/name");
strVal = (String) pro.getProperty(key); return strVal; } /** * 释放资源 */ public static void ReleaseSoucre(ResultSet rs, Statement stmt, Connection conn) { try { if (rs != null) rs.close(); if ...
String email = pfR.getValueByPropertyKey("name"); System.out.println(email); String key = "name"; String value = "xbl"; pfR.setValue(key, value, "This is my name "); } }
$system ->getProperty( 'os.name' ). ' ' . $system ->getProperty( 'os.version' ). ' on ' . $system ->getProperty( 'os.arch' ). ' ' ; // java.util.Date example $formatter = new Java( 'java.text...