Get the path method for a file or folder in Java

Source: Internet
Author: User

gets the project path where the current class is located, if not added "/the File F=NewFile ( This. GetClass (). GetResource (""). GetPath ()); System.out.println (f); results: C:\Documents%20and%20settings\administrator\workspace\projectname\bin\com\test Gets the absolute path of the current class, and the second: File directory=NewFile ("");//parameter is emptyString Coursefile =Directory.getcanonicalpath (); System.out.println (coursefile); Result: C:\Documents and Settings\administrator\workspace\projectname gets the project path where the current class is located; The third type: URL xmlpath= This. GetClass (). getClassLoader (). GetResource ("Selected.txt"); System.out.println (Xmlpath); results: File:/c:/documents%20and%20settings/administrator/workspace/projectname/bin/Selected.txt Gets the path to the Selected.txt file in the current project SRC directory Fourth: System.out.println (System.getproperty ("User.dir"); results: C:\Documents and Settings\administrator\workspace\projectname get the current project path fifth type: System.out.println ( System.getproperty ("Java.class.path"); Result: C:\Documents and Settings\administrator\workspace\projectname\bin get the current project path

Get the path method for a file or folder in Java

Related Article

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.