Ways to get paths from Java

Source: Internet
Author: User

  1. Package COM.ZJF;
  2. import java.io.File;
  3. Public class GetPath {
  4. Public Static void GetPath ()
  5. {
  6. Way One
  7. System.out.println (System.getproperty ("User.dir"));
  8. Way Two
  9. File directory = new file ("");//Set as current folder
  10. Try {
  11. System.out.println (Directory.getcanonicalpath ());//Get the standard path
  12. System.out.println (Directory.getabsolutepath ());//Get absolute path
  13. }catch(Exception e)
  14. {
  15. E.printstacktrace ();
  16. }
  17. Mode three
  18. System.out.println (GetPath. Class. GetResource ("/"));
  19. System.out.println (GetPath. Class. GetResource (""));
  20. Mode Four
  21. System.out.println (GetPath. Class. getClassLoader (). GetResource (""));
  22. System.out.println (GetPath. Class. getClassLoader (). GetResource ("Source.xml"));
  23. }
  24. Public Static void Main (string[] args) {
  25. Getpath.getpath ();
  26. }

35.}

Ways to get paths from Java

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.