Some methods in Java that get the absolute path of the classpath and the current class (%20 in the path replaces spaces)

Source: Internet
Author: User

Original website: http://blog.csdn.net/shendl/article/details/1427475(Note: Use the following method to get the path, if there is a space character in the path, then there will be "%20" to replace, so you can then replace "%20 " with a space)Here are some ways to get the absolute path of classpath and the current class. You may need to use some of these methods to get the absolute path of the resources you need. 1 , FileTest.class.getResource (""); FileTest.class.getResource (".. /");//Get the upper level The URI directory of the current class Filetest.class file is obtained. Don't include yourself! such as: file:/d:/java/eclipse32/workspace/jbpmtest3/bin/com/test/ 2 , FileTest.class.getResource ("/")Gets the absolute URI path of the current classpath. such as: file:/d:/java/eclipse32/workspace/jbpmtest3/bin/ 3 , Thread.CurrentThread (). Getcontextclassloader (). GetResource ("")The resulting absolute URI path is also the current classpath. such as: file:/d:/java/eclipse32/workspace/jbpmtest3/bin/ 4 , FileTest.class.getClassLoader (). GetResource ("")The resulting absolute URI path is also the current classpath. such as: file:/d:/java/eclipse32/workspace/jbpmtest3/bin/ 5 , Classloader.getsystemresource ("")The resulting absolute URI path is also the current classpath. such as: file:/d:/java/eclipse32/workspace/jbpmtest3/bin/     I recommend using Thread.CurrentThread (). Getcontextclassloader (). GetResource ("") to get the URI representation of the absolute path of the current classpath.

Some methods in Java that get the absolute path of the classpath and the current class (%20 in the path replaces spaces)

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.