• properties类的基本使用方法


    properties类的基本使用方法
    1.假设有“pp.properties”,内容有   
        
    age=22   
        
    2.java中用下面方法:   
    Properties   props   =   new   Properties();   
    props.load(new   FileInputStream(new   File("pp.properties")));   
    String   age="";   
    age=props.getProperty("age");

    Properties   props   =   new   Properties();//创建一个Properties对象   
    //把文件pp.properties转化为一个文件输入流(从文件到系统为输入流),然后Properties加载输入流;   
    props.load(new   FileInputStream(new   File("pp.properties")));   
    String   age="";   
    //从Properties中读取属性....   
    age=props.getProperty("age");  

    基本上时用来读取配置文件的内容用的   
    还有就是:   
    Properties   p=System.getProperties();   
    来读取一些系统信息:   
    Key   Description   of   Associated   Value     
    java.version   Java   Runtime   Environment   version   

    os版本用System.getProperty("os.version");   
    ie版本用request.getHeader("...")//忘了

    System.getProperty("os.name")   
        显示操作系统  


    Properties对象来包含keys和values。一个key对应一个value,例如:   
        
    country1     -->     China   
    country2     -->     France   
    country3     -->     Kre   
        
    你就可以用Properties把他们放一起了:   
                                          Properties   prop   =   new   Properties();   
             //放值的时候    
    prop.put("country1","China");   
    prop.put("country2","France");   
    prop.put("country3","Kr");   
    //取值的时候呢   
    String   test=   prop.getProperty("country1");   
    这样test的值就是country1对应的值China了。   
    put,getProperty方法是这个类的最简单用法。当然还有其他更好用的方法,慢慢去看jdk文档了,先理解理解。

  • 相关阅读:
    阻止用户复制页面上的文字的几种方法
    js设置聊天信息停留在最底部
    js动态删除表格中的某一行
    XmlSerializer vs DataContractSerializer: Serialization in Wcf
    WCF Service Binding Explained
    Visual Studio设置远程调试
    Could not download the Silverlight application
    .NET 中的三种接口实现方式
    化零为整WCF(9) 序列化(DataContractSerializer, XmlSerializer, DataContractJsonSerializer, SoapFormatter, BinaryFormatter)
    化零为整WCF(14) 事务(Transaction)
  • 原文地址:https://www.cnblogs.com/wnlja/p/3929680.html
Copyright © 2020-2023  润新知