src下面新建demo.properties
level=debug
@Test
public void test05() throws Exception{
InputStream in = new BufferedInputStream(new FileInputStream("src/demo.properties")) ;
Properties p = new Properties();
p.load(in);
String level =p.getProperty("level");
System.out.println(level);
}
@Test
public void test06() throws IOException{
InputStream in=Properties.class.getResourceAsStream("/demo.properties");
Properties p = new Properties();
p.load(in);
System.out.println(p.getProperty("level"));
}
@Test
public void test07() throws IOException{
InputStream in = FileTest.class.getClassLoader().getResourceAsStream("demo.properties");
Properties p = new Properties();
p.load(in);
System.out.println(p.getProperty("level"));
}
@Test
public void test08() throws IOException{
InputStream in =ClassLoader.getSystemResourceAsStream("demo.properties");
Properties p = new Properties() ;
p.load(in) ;
System.out.println(p.getProperty("level"));
}
InputStream in = MyTest.class.getClassLoader().getResourceAsStream("a.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line = null;
while( (line = br.readLine()) != null ){
System.out.println(line);
}
br.close();
in.close();
String filePath = MTest.class.getResource("/a.txt").getPath();
filePath = filePath.substring(1);
InputStream in = new FileInputStream(new File(filePath));
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String str = null;
while( (str = br.readLine())!=null ){
System.out.println(str);
}
in.close();
br.close();