zoukankan      html  css  js  c++  java
  • java读取properties配置文件

     1 import java.io.BufferedReader;
     2 import java.io.FileInputStream;
     3 import java.io.IOException;
     4 import java.io.InputStream;
     5 import java.io.InputStreamReader;
     6 import java.util.Properties;
     7 
     8 /** 
     9  * @author Chase QQ: 594126573
    10  * @version 创建时间:2012-5-11   下午02:28:36
    11  * 类说明 
    12  */
    13 
    14 public class test {
    15     public static void main(String[] args)  {
    16         
    17         test2();
    18     }
    19     
    20     public static void test1() throws IOException{
    21         String file = "E:\\workspace7.01\\JspFileUpload\\src\\System.properties";
    22          InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file),"utf-8");
    23          BufferedReader br = new BufferedReader(inputStreamReader);
    24          String s;
    25         try {
    26             while ((s = br.readLine())!= null) {
    27                 System.out.println(s);
    28             }
    29         } catch (Exception e) {
    30             e.printStackTrace();
    31         }
    32         
    33     }
    34     
    35     public static void test2(){
    36         InputStream inputStream = new test().getClass().getClassLoader().getResourceAsStream("System.properties");   
    37           Properties p = new Properties();   
    38           try {   
    39            p.load(inputStream);   
    40           } catch (IOException e1) {   
    41            e1.printStackTrace();   
    42           }   
    43         System.out.println("TgUpLoadPath"+p.getProperty("TgUpLoadPath")+",TgUpLoadPath:"+p.getProperty("TgUpLoadPath"));  
    44     }
    45     
    46 }
  • 相关阅读:
    Linux磁盘系统——管理磁盘的命令
    Linux磁盘系统——磁盘系统简介
    LinuxShell——内嵌命令
    安装PHP出现make: *** [sapi/cli/php] Error 1 解决办法
    Linux常用命令
    Linux文件系统及文件类型
    MySQL查询语句
    Python随手记—各种方法的使用
    MySQL架构及SQL语句
    Python笔记记录
  • 原文地址:https://www.cnblogs.com/chasewade/p/2968951.html
Copyright © 2011-2022 走看看