The GetResource method of Java

Source: Internet
Author: User
The 1 GetResource method is the function that gets the file path.
such as: String Value=testmain2.class.getresource ("/a.properties"). ToString ();
This is the path to get the a.properties under SRC.


2 If the method argument starts with the SRC root in the beginning of "/", the lookup is started. If it does not begin with "/", the lookup is started from the package of the current class.
such as: String Value=testmain2.class.getresource ("/a.properties"). ToString ();--Start looking from SRC
String Value=test.class.getresource ("Aaa.xml"). ToString ()--start looking from the package where the current class resides


3 by "class name. Class.getResource (String string)". With class name
such as: String Value=testmain2.class.getresource ("/a.properties"). ToString ();


4 If you want to find the directory where the current project is located, the parameter is: "/".
such as: String Value=test.class.getresource ("/"). ToString ();


5 If you want to find the directory where the current class resides. Then the argument is: "". is an empty string.
such as: String Value=test.class.getresource (""). ToString ();




To sum up, the GetResource function can get the file under SRC, also can get the current class under the package of files.
You can also get the directory where the current project is located, or you can get the directory where the current class resides.

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.