標籤: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
- ip=127.0.0.1
運行程式,控制台列印出結果
Java解析property檔案(和靜哥說的,SQL執行限定時間寫在xml中,增加擴充,在不改原始碼基礎上)