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/..