How to obtain the file path in Java
2., using System. the getProperty () function obtains the current path: System. out. println (System. getProperty ("user. dir "); // user. dir specifies the current path </p> <p> 2. Use the function provided by File to obtain the current path: File directory = new File (""); // set it to the current folder try {System. out. println (directory. getCanonicalPath (); // obtain the standard path System. out. println (directory. getAbsolutePath (); // obtain the absolute path} catch (shorttin e) {}</p> <p> File. getCanonicalPath () and File. getAbsolutePath () is about (". ") and new File (".. ") Two paths Yes. </P> <p> # For the getCanonicalPath () function, "indicates the current folder, and ".. "indicates the upper-level folder of the current folder # For the getAbsolutePath () function, no matter ". ","... ", returns the current path with the path you set when new File () # As for the getPath () function, all you get is in the new File () path </p> <p> for example, the current path is C: \ test: File directory = new File ("abc"); directory. getCanonicalPath (); // C: \ test \ abcdirectory. getAbsolutePath (); // The result is C: \ test \ abcdirecotry. getPath (); // abc </p> <p> File directory = new File (". "); directory. getCanonicalPath (); // The result is C: \ testdirectory. getAbsolutePath (); // The result is C: \ test \. direcotry. getPath (); // The result is. </p> <p> File directory = new File (".. "); directory. getCanonicalPath (); // C: \ directory. getAbsolutePath (); // The result is C: \ test \.. direcotry. getPath (); // The result is .. </p> <p> In addition: System. the string parameters in getProperty () are as follows: </p> <p> System. getProperty () parameter description # java. version Java Runtime Environment version # java. vendor Java Runtime Environment vendor # java. vendor. url Java vendor URL # java. home Java installation directory # java. vm. specification. version Java Virtual Machine specification version # java. vm. specification. vendor Java Virtual Machine specification vendor # java. vm. specification. name Java Virtual Machine specification name # java. vm. version Java Virtual Machine implementation version # java. vm. vendor Java Virtual Machine implementation vendor # java. vm. name Java Virtual Machine implementation name # java. specification. version Java Runtime Environment specification version # java. specification. vendor Java Runtime Environment specification vendor # java. specification. name Java Runtime Environment specification name # java. class. version Java class format version number # java. class. path Java class path # java. library. path List of paths to search when loading libraries # java. io. tmpdir Default temp file path # java. compiler Name of JIT compiler to use # java. ext. dirs Path of extension directory or directories # OS. name Operating system name # OS. arch Operating system architecture # OS. version Operating system version # file. separator File separator ("/" on UNIX) # path. separator Path separator (":" on UNIX) # line. separator Line separator ("\ n" on UNIX) # user. name User's account name # user. home User's home directory # user. dir User's current working directory </p>