`
lengyingxin
  • 浏览: 57387 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Java如何读取properties文件

 
阅读更多
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
import java.util.Enumeration;


public final class Test
{
    private static Properties props = new Properties();

    static public void main(String args[]) throws Exception{
        try{
            FileInputStream inStream = new FileInputStream(new File("dd"));
            
			try
			{
				props.load(inStream);
			}
			finally
			{
				inStream.close();
			}
        Enumeration enumKeys = props.keys();
        String key, value = null;

             while (enumKeys.hasMoreElements()){
                    key = (String) enumKeys.nextElement();
                    value = props.getProperty(key, "").trim();

                    System.setProperty(key, value);
                    }
            }catch (RuntimeException e){
                e.printStackTrace();
            }
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics