zoukankan      html  css  js  c++  java
  • Java解析Property文件

    在Java项目中一些配置參数保存在Property文件里,这样能保证不改动原代码直接改动Property文件。

    PropertyParser.java

    package com.discover.parse;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.util.Properties;
    
    /**
     * @author Administrator
     *
     */
    public class PropertyParser {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Properties properties = new Properties();
            String name = PropertyParser.class.getResource("").getPath();
            String path = name + "config.properties";
            File file = new File(path);
            if(file.exists())
            {
                try{
                    InputStream fis = new FileInputStream(file);
                    properties.load(fis);
                    System.out.println(properties.getProperty("ip"));
                fis.close();
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        }
    }

    config.properties

    ip=127.0.0.1

    执行程序,控制台打印出结果



  • 相关阅读:
    mybatis-spring 集成
    maven 插件深入了解
    maven 常用插件3
    maven 插件2
    <转载> maven 详解 http://www.cnblogs.com/binyue/p/4729134.html
    linux base shell 基础语法
    浏览器运行原理
    <转载> js 闭包
    dubbo 学习资料
    HTTP
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6791746.html
Copyright © 2011-2022 走看看