packagecom.java.demo;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;publicclassDemo3{publicstaticvoidmain(String[] args)throwsIOException{ClassLoader c =Demo3.class.getClassLoader();System.out.println(c);//class.getClassLoader().getResourceAsStream 会默认优先到文件类型为Test Resources Root//的文件夹下查找InputStream is =Demo3.class.getClassLoader().getResourceAsStream("config.txt");BufferedReader br =newBufferedReader(newInputStreamReader(is));String text = br.readLine();System.out.println(text);
br.close();}}