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 }
  • 相关阅读:
    转载阿里开源的分布式事务框架 Seata
    查看进程上的线程数量
    chmod命令
    查找端口与查找正在运行的进程
    可输入的文本框
    js 类和对象
    js 三维数组
    ajax
    ORACLE数据库主要的系统表和数据字典视图
    url 传参
  • 原文地址:https://www.cnblogs.com/chasewade/p/2968951.html
Copyright © 2011-2022 走看看