1 import java.io.FileReader; 2 import java.io.InputStream; 3 import java.util.Properties; 4 5 public class IoPropertiesTest { 6 public static void main(String[] args) throws Exception{ 7 8 // 获取一个文件的绝对路径了!!!!! 9 /*String path = Thread.currentThread().getContextClassLoader() 10 .getResource("classinfo2.properties").getPath(); 11 FileReader reader = new FileReader(path);*/ 12 13 // 直接以流的形式返回。 14 InputStream reader = Thread.currentThread().getContextClassLoader() 15 .getResourceAsStream("classinfo2.properties"); 16 17 Properties pro = new Properties(); 18 pro.load(reader); 19 reader.close(); 20 // 通过key获取value 21 String className = pro.getProperty("className"); 22 System.out.println(className); 23 } 24 }