Path issues in Java
Code description, as follows:
Packagecom.merlin.test;ImportJava.io.InputStream; Public classTest { Public Static voidMain (string[] args) {NewTest (). Testpath (); } Public voidTestpath () {//when using the getResourceAsStream () method, the root path refers to Classpath, which is the SRCInputStream In0 = This. GetClass (). getResourceAsStream ("/");//Note that the backslash is writtenSystem.out.println (IN0);//can read to the//not applicable when followed by path, is the class file pathInputStream in1 = This. GetClass (). getResourceAsStream ("A.xml");//Note that the backslash is writtenSystem.out.println (in1);//can read to theInputStream in2 = This. GetClass (). getResourceAsStream ("/b.xml");//Note that the backslash is writtenSystem.out.println (in2);//can read to theInputStream in3= This. GetClass (). getResourceAsStream ("/a.xml");//Note that the backslash is writtenSystem.out.println (in3);//cannot read }}
Path issues in Java