2.2.1 create a Path, 2.2.1 create a path

Source: Internet
Author: User

2.2.1 create a Path, 2.2.1 create a path

Demo:

Import java. nio. file. path; import java. nio. file. paths; /*** @ author jinxing * @ system mac OS X * @ Use Case 1 [use] absolute path * @ Use Case 2 [use] relative path * @ Use Case 3 relative path [convert] absolute path * @ Conclusion 1 [use] relative path, the opposite is [.. project File/bottom file to which the current file belongs]; * @ conclusion 2 the result is the same no matter whether it is added or not [/backslash]; (it is better not to add it) */public class PathTest {// The IOExcetion public static void main (String [] args) exception thrown by various methods in Path or Paths) {// [use] absolute Path useabs = Paths. get ("/Users/jinxing/Documents/pathtest"); Path useabsz = Paths. get ("/Users/jinxing/Documents/pathtest/"); // [use] Relative Path userel = Paths. get (".. "); Path userelz = Paths. get (".. /"); // relative Path [converted to] absolute Path relToAbs = userel. toAbsolutePath (); Path relToAbsz = userelz. toAbsolutePath (); // show System. out. println (useabs. toString (); System. out. println (useabsz. toString (); System. out. println (userel. toString (); System. out. println (userelz. toString (); System. out. println (relToAbs. toString (); System. out. println (relToAbsz. toString ());}}

Ran As Java Application:

/Users/jinxing/Documents/pathtest/Users/jinxing/Documents/pathtest..../Users/jinxing/Documents/workspace/nio.2/../Users/jinxing/Documents/workspace/nio.2/..

 

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.