package com.heima.userJSTL; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Properties; public class PropretiesDemo { public static void main(String[] args) throws Exception { //当使用字节流的时候默认的目录是当前模块下(eclipse默认是项目下) FileInputStream fis = new FileInputStream("a.properties"); Properties prop = new Properties(); prop.load(fis); String username = prop.getProperty("username"); System.out.println(username); //当使用类加载器以流的方式加载文件时,默认的目录是当前模块的src下 ClassLoader classLoader = PropretiesDemo.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream("b.properties"); Properties prop2 = new Properties(); prop2.load(is); String property = prop2.getProperty("username"); System.out.println(property); } }