码迷,mamicode.com
首页 > 数据库 > 详细

Java解析property文件(和静哥说的,SQL执行限定时间写在xml中,增加扩展,在不改源代码基础上)

时间:2017-09-05 01:46:10      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:new   解析   int   out   todo   inpu   main   image   parser   

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

 [plain] view plain copy

    1. ip=127.0.0.1 
      运行程序,控制台打印出结果

      技术分享

       

Java解析property文件(和静哥说的,SQL执行限定时间写在xml中,增加扩展,在不改源代码基础上)

标签:new   解析   int   out   todo   inpu   main   image   parser   

原文地址:http://www.cnblogs.com/cs-lcy/p/7476569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!