Read resources from the JAR package

Source: Internet
Author: User

Tag: src Throw string address static enc getc [] except

 PackageMyspider; 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")); }  }  
        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  


String jstring = JsonUtil.class.getResource ("/createareabatchorderaddress.json"). GetPath ();

Hit into a jar package, read
Createareabatchorderaddress.json file

Read resources from the JAR package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.