zoukankan      html  css  js  c++  java
  • java的System.getProperty()方法可以获取的值

    java.version

    Java 运行时环境版本

    java.vendor

    Java 运行时环境供应商

    java.vendor.url

    Java 供应商的 URL

    java.home

    Java 安装目录

    java.vm.specification.version

    Java 虚拟机规范版本

    java.vm.specification.vendor

    Java 虚拟机规范供应商

    java.vm.specification.name

    Java 虚拟机规范名称

    java.vm.version

    Java 虚拟机实现版本

    java.vm.vendor

    Java 虚拟机实现供应商

    java.vm.name

    Java 虚拟机实现名称

    java.specification.version

    Java 运行时环境规范版本

    java.specification.vendor

    Java 运行时环境规范供应商

    java.specification.name

    Java 运行时环境规范名称

    java.class.version

    Java 类格式版本号

    java.class.path

    Java 类路径

    java.library.path

    加载库时搜索的路径列表

    java.io.tmpdir

    默认的临时文件路径

    java.compiler

    要使用的 JIT 编译器的名称

    java.ext.dirs

    一个或多个扩展目录的路径

    os.name

    操作系统的名称

    os.arch

    操作系统的架构

    os.version

    操作系统的版本

    file.separator

    文件分隔符(在 UNIX 系统中是“/”)

    path.separator

    路径分隔符(在 UNIX 系统中是“:”)

    line.separator

    行分隔符(在 UNIX 系统中是“/n”)

    user.name

    用户的账户名称

    user.home

    用户的主目录

    user.dir

    用户的当前工作目录

    获取的代码示例:

    public class SystemProperty {  
        public static void main(String args[]) {     
            System.out.println("java_vendor:" + System.getProperty("java.vendor"));     
            System.out.println("java_vendor_url:" + System.getProperty("java.vendor.url"));     
            System.out.println("java_home:" + System.getProperty("java.home"));     
            System.out.println("java_class_version:" + System.getProperty("java.class.version"));     
            System.out.println("java_class_path:" + System.getProperty("java.class.path"));     
            System.out.println("os_name:" + System.getProperty("os.name"));     
            System.out.println("os_arch:" + System.getProperty("os.arch"));     
            System.out.println("os_version:" + System.getProperty("os.version"));     
            System.out.println("user_name:" + System.getProperty("user.name"));     
            System.out.println("user_home:" + System.getProperty("user.home"));     
            System.out.println("user_dir:" + System.getProperty("user.dir"));     
            System.out.println("java_vm_specification_version:" + System.getProperty("java.vm.specification.version"));     
            System.out.println("java_vm_specification_vendor:" + System.getProperty("java.vm.specification.vendor"));     
            System.out.println("java_vm_specification_name:" + System.getProperty("java.vm.specification.name"));     
            System.out.println("java_vm_version:" + System.getProperty("java.vm.version"));     
            System.out.println("java_vm_vendor:" + System.getProperty("java.vm.vendor"));     
            System.out.println("java_vm_name:" + System.getProperty("java.vm.name"));     
            System.out.println("java_ext_dirs:" + System.getProperty("java.ext.dirs"));     
            System.out.println("file_separator:" + System.getProperty("file.separator"));     
            System.out.println("path_separator:" + System.getProperty("path.separator"));     
            System.out.println("line_separator:" + System.getProperty("line.separator"));     
        }
    }
    

     

    1、java 通过System.getProperties()获取系统参数

     

       Properties props=System.getProperties(); //系统属性 
       System.out.println("Java的运行环境版本:"+props.getProperty("java.version"));
       System.out.println("Java的运行环境供应商:"+props.getProperty("java.vendor"));
       System.out.println("Java供应商的URL:"+props.getProperty("java.vendor.url"));
       System.out.println("Java的安装路径:"+props.getProperty("java.home"));
       System.out.println("Java的虚拟机规范版本:"+props.getProperty("java.vm.specification.version"));
       System.out.println("Java的虚拟机规范供应商:"+props.getProperty("java.vm.specification.vendor"));
       System.out.println("Java的虚拟机规范名称:"+props.getProperty("java.vm.specification.name"));
       System.out.println("Java的虚拟机实现版本:"+props.getProperty("java.vm.version"));
       System.out.println("Java的虚拟机实现供应商:"+props.getProperty("java.vm.vendor"));
       System.out.println("Java的虚拟机实现名称:"+props.getProperty("java.vm.name"));
       System.out.println("Java运行时环境规范版本:"+props.getProperty("java.specification.version"));
       System.out.println("Java运行时环境规范供应商:"+props.getProperty("java.specification.vender"));
       System.out.println("Java运行时环境规范名称:"+props.getProperty("java.specification.name"));
       System.out.println("Java的类格式版本号:"+props.getProperty("java.class.version"));
       System.out.println("Java的类路径:"+props.getProperty("java.class.path"));
       System.out.println("加载库时搜索的路径列表:"+props.getProperty("java.library.path"));
       System.out.println("默认的临时文件路径:"+props.getProperty("java.io.tmpdir"));
       System.out.println("一个或多个扩展目录的路径:"+props.getProperty("java.ext.dirs"));
       System.out.println("操作系统的名称:"+props.getProperty("os.name"));
       System.out.println("操作系统的构架:"+props.getProperty("os.arch"));
       System.out.println("操作系统的版本:"+props.getProperty("os.version"));
       System.out.println("文件分隔符:"+props.getProperty("file.separator"));   //在 unix 系统中是"/"
       System.out.println("路径分隔符:"+props.getProperty("path.separator"));   //在 unix 系统中是":"
       System.out.println("行分隔符:"+props.getProperty("line.separator"));   //在 unix 系统中是"/n"
       System.out.println("用户的账户名称:"+props.getProperty("user.name"));
       System.out.println("用户的主目录:"+props.getProperty("user.home"));
       System.out.println("用户的当前工作目录:"+props.getProperty("user.dir"));

     

    2、用Java编写通过代理访问的应用程序

     

    本技巧将向您讲述如何编写可通过代理访问因特网上的Web服务器的Java应用程序。在Java应用程序中加入代理支持只需额外编写几行代码,且不依赖任何安全性“漏洞”。

    将Java和代理结合起来的秘诀即在Java运行时激活特定的系统属性。这些属性未被写入正式文件,只是作为Java传说的一部分在Java编程人员中秘传。为了支持代理,Java应用程序不仅需要指定代理本身的信息,而且需要指定用于认证的用户信息。在开始使用网际协议之前,您需要在程序中添加以下几行代码:
    //通知Java您要通过代理进行连接

    System.getProperties().put("proxySet","true");

    //指定代理所在的服务器

    System.getProperties().put("proxyHost","myProxyMachineName");

    //指定代理监听的端口

    System.getProperties().put("proxyPort","85");

    有些代理在授权用户访问因特网之前,要求用户输入用户名和口令。如果您使用位于防火墙之内的Web浏览器,您就可能碰到过这种情况。以下是执行认证的方法:
    URLConnection  connection=url.openConnection(); 
    String   password="username:password"; 
    String   encodedPassword=base64Encode(password); 
    connection.setRequestProperty("Proxy-Authorization",encodedPassword);

    这段代码的思想是,您必须调整HTTP标头以发出用户信息。这是通过调用setRequestProperty()来实现的。这种方法允许您在发出请求之前处理HTTP标头。HTTP要求用base64对用户名和口令进行编码。幸运的是,有一组公用域API,它们将代您执行编码(请参阅参考资源部分)。

    如您所见,在Java应用程序中加入代理支持并不需要做多少工作。有了现在的知识,再做一点研究(您必须查明您的代理是如何处理您感兴趣的协议以及如何进行用户认证的),您就能用其他协议实现代理。
        HTTP代理:(例子)
    Properties props = System.getProperties();
    props.put("http.proxyHost", "192.168.0.150");
    props.put("http.proxyPort", "808");

        FTP代理

        ScottD.Taylor提出这个秘诀来处理FTP协议代理:

    defaultProperties.put("ftpProxySet","true"); 
    defaultProperties.put("ftpProxyHost","proxy-host-name"); 
    defaultProperties.put("ftpProxyPort","85");
    接下来您便可以通过以下代码使用"ftp"协议访问文件URL:

    URL  url=newURL("ftp://ftp.netscape.com/pub/navigator/3.04/windows/readme.txt");

    如果有人有使用其他网际协议代理的例子,我很想看看。

    注意:代码示例(Example.java)仅在JDK1.1.4下测试过。

    后续技巧!

    对于仍在使用JDK1.1.7(配合WebSphere3.0)的开发人员而言,将proxyHost和proxyPort设为系统属性不起作用;conn.getInputStream()或者返回连接超时,或者是找不到主机路径。但是,我使用接受Host和Port为参数的URL构造函数解决了这一问题(使用我的代理主机和端口):

    public  URL(String  protocol,String  host,int port,String  file).

    借助用户名和口令进行认证的方法不起作用。应将"Basic"置于认证字符串的开头;例如:

    String  encodedPassword=base64Encode(password);

    应该是:

    String  encodedPassword="Basic"+base64Encode(password);

    您也不必用一个单独的程序来进行64位编码。您可以使用sun.misc.BASE64Encoder()类。下面是完成这两处改动之后的代码:

    System.getProperties().put("proxySet","true"); 
    System.getProperties().put("proxyHost",proxyHost); 
    System.getProperties().put("proxyPort",proxyPort); 
    String  authString="userid:password"; 
    String  auth="Basic"+newsun.misc.BASE64Encoder().encode(authString.getBytes()); 
    URL url=newURL("http://java.sun.com/"); 
    URLConnection  conn=url.openConnection(); 
    conn.setRequestProperty("Proxy-Authorization",auth);
    下面是使用socks4代理服务器的方法:


    System.getProperty("socksProxySet",true); 
    System.getProperty("socksProxyHost",proxyHostName); 
    System.getProperty("socksProxyPort",proxyPort);
    Usually  the  proxyPort  for  Socks 4  is  port  1080
  • 相关阅读:
    [转载]Nginx 常见应用技术指南
    【转载】Memcached Tip 2:Session同步
    【转载】大规模网站架构实战之体系结构
    【转载】3种Nginx防盗链的方法
    poj2390
    poj2395
    poj2393
    poj2209
    poj2392
    爱我更多,好吗?
  • 原文地址:https://www.cnblogs.com/cRaZy-TyKeIo/p/3543281.html
Copyright © 2011-2022 走看看