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

     1 package com.test;
     2 
     3 import java.util.Properties;
     4 import java.io.InputStream;
     5 import java.io.IOException;
     6 
     7 public final class ReadPropertiesUtil {
     8     private static String param1;
     9     private static String param2;
    10 
    11     static {
    12         Properties prop = new Properties();
    13 //        InputStream in1 = Object.class.getResourceAsStream("/com/property/test.properties");
    14 //        InputStream in2 = ReadPropertiesUtil.class.getResourceAsStream("/com/property/test.properties");
    15         InputStream in3 = ReadPropertiesUtil.class.getClassLoader().getResourceAsStream("com/property/test.properties");  
    16         try {
    17             prop.load(in3);
    18             param1 = prop.getProperty("name").trim();
    19             param2 = prop.getProperty("password").trim();
    20         } catch (IOException e) {
    21             e.printStackTrace();
    22         }
    23     }
    24 
    25     /**
    26      * 私有构造方法,不需要创建对象
    27      */
    28     private ReadPropertiesUtil() {
    29     }
    30 
    31     public static String getParam1() {
    32         return param1;
    33     }
    34 
    35     public static String getParam2() {
    36         return param2;
    37     }
    38 
    39     public static void main(String args[]) {
    40         System.out.println(getParam1());
    41         System.out.println(getParam2());
    42     }
    43 }
  • 相关阅读:
    MySQL
    面向对象总结
    git指令
    DOS命令
    补充
    如何处理数据
    操作php数据库
    git安装方法
    git知识点/下一章是git的安装方法
    Css3属性
  • 原文地址:https://www.cnblogs.com/luomsg/p/5027874.html
Copyright © 2011-2022 走看看