PropertiesUtil
1 package com.jf.utils; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.io.InputStream; 6 import java.io.InputStreamReader; 7 import java.util.Properties; 8 9 /** 10 * 读取配置文件 11 * 12 */ 13 public class PropertiesUtils { 14 public static Properties props = null; 15 16 private PropertiesUtils(){} 17 18 static{ 19 String fileName = "ftp.properties"; 20 props = new Properties(); 21 InputStream inputStream = PropertiesUtils.class.getClassLoader().getResourceAsStream(fileName); 22 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); 23 try { 24 props.load(bufferedReader); 25 inputStream.close(); 26 } catch (IOException e) { 27 e.printStackTrace(); 28 } 29 } 30 31 public static void main(String[] args) { 32 System.out.println(PropertiesUtils.props.get("")); 33 } 34 35 public static String getProperty(String key){ 36 return props.getProperty(key); 37 } 38 39 }