zoukankan      html  css  js  c++  java
  • 集合_Properties


    写配置信息

    public class PropertiesJava {
         public static void main(String[] args) throws IOException{
               String path = "d:" + File.separator + "javatest" + File.separator +"PropertiesT.txt";
               File f = new File(path);
               OutputStream out = new FileOutputStream(f);
               //PrintStream ps = new PrintStream(new FileOutputStream(f));
               Properties p = new Properties();
               p.setProperty("name", "zed");
               p.setProperty("age", "zed");
               p.setProperty("pass", "zed");
               
               //list()方法只能输出打印流,而store()方法只要是输出流就可以,使用store方法
               //store()方法属性列表信息更详细
               //p.list(ps);
               p.store(out, "comments");
               out.close();
         }
    }
    

    读配置信息

    public class PropertiesJava {
         public static void main(String[] args) throws IOException{
               String path = "d:" + File.separator + "javatest" + File.separator +"PropertiesT.txt";
               File f = new File(path);
               InputStream in = new FileInputStream(f);
               
               Properties p = new Properties();
               p.load(in);
               Enumeration<?> en = p.propertyNames();
               while(en.hasMoreElements()) {
                    String strKey = (String)en.nextElement();
                    String strValue = p.getProperty(strKey);
                    System.out.println(strKey + " = " + strValue);
               }
               
               System.out.println("------------------");
               
               //已知key求value
               String strAge = p.getProperty("age");
               String strName = p.getProperty("name");
               System.out.println(strName);
               System.out.println(strAge);
               
               in.close();
               
         }
    }
    
  • 相关阅读:
    php_sphinx安装使用
    获取数据库中所有表名
    总结thinkphp快捷查询getBy、getField、getFieldBy用法及场景
    打印机复印身份证方法
    svn 删除、移动和改名
    MySQL中REGEXP正则表达式使用大全
    高铁在高速运行时的电力是如何提供的?
    2016亚洲大学排名
    Mac下安装HBase及详解
    HBase Mac OSX 安装笔记
  • 原文地址:https://www.cnblogs.com/changzuidaerguai/p/9280069.html
Copyright © 2011-2022 走看看