Transfer from--->http://ouyangfei0426.iteye.com/blog/1020232
SRC (source folder)
┃
┣━11.properties
┃
┗━myspider (Myspider bag)
┃
┣━22.properties
┗━test.java
Importjava.io.UnsupportedEncodingException; /** * * @authorMark*/ Public classTest { Public Static voidMain (string[] args)throwsunsupportedencodingexception{Test T=NewTest (); //A "/" is not added to the file name, which means that the resource is located under the same package as the current class. The following is a look at the 22.properties file resource from the package Myspider. System.out.println ("1:" +t.getclass (). getResourceAsStream ("22.properties"));//output [email protected]//a "/" is added to the file name, which means that the resource is looked up from the Classpath under the Classes folder, as follows to find the 22.properties file resource from the Classes folder. System.out.println ("2:" +t.getclass (). getResourceAsStream ("/22.properties"));//output NULL//a "/" is added to the file name, which means that the resource is looked up from the Classpath under the Classes folder, as follows to find the 11.properties file resource from the Classes folder. System.out.println ("3:" +t.getclass (). getResourceAsStream ("/11.properties"));//output [email protected]System.out.println (); //Current package path 4:file:/e:/myobject/myspider/build/classes/myspider/System.out.println ("4:" +t.getclass (). GetResource ("")); //outputs the current classpath 5:file:/e:/myobject/myspider/build/classes/System.out.println ("5:" +t.getclass (). GetResource ("/")); /** If the current package under the Classpath has a 22.properties file, the output 6:file:/e:/myobject/myspider/build/classes/myspider/22.properties * The path of the 22.properties file under the output source file is output: 6:file:/e:/myobject/myspider/src/myspider/22.properties*/System.out.println ("6:" +t.getclass (). GetResource ("22.properties")); /** If there is a 11.properties file under the classpath, the output 7:file:/e:/myobject/myspider/build/classes/11.properties * No is 11 under the output source file. The path of the properties file, the output: 6:7:file:/e:/myobject/myspider/src/11.properties*/System.out.println ("7:" +t.getclass (). GetResource ("/11.properties")); } }
Java path Problem (i)--getclass (). getResourceAsStream ()