Java gets the current path 1, using the System.getproperty () function to get the current path:
System.out.println (
system.getproperty ("User.dir"));//user.dir specifies the current path
2. Use the function provided by file to get the current path:
file directory = new file ("");Set as current folder
try{
System.out.println (
Directory.getcanonicalpath ());//Get the standard path
System.out.println (
Directory.getabsolutepath ());//Get absolute path
}catch (Exceptin e) {}
File.getcanonicalpath () and File.getabsolutepath () are only about
New File (".")And
New File ("..")The two paths differ.
# for the Getcanonicalpath () function, "
."Represents the current folder, and the"
.."Represents the top level folder in the current folder
# for the GetAbsolutePath () function, regardless of the "
.”、“
..", return the current path plus the path you set at New File ()
# As for the GetPath () function, you get only the path you set at the new File ()
For example, the current path is C:\test:
file directory = new file ("abc");
Directory.getcanonicalpath ();Got to be
C:\TEST\ABC
Directory.getabsolutepath ();Got to be
C:\TEST\ABC
Direcotry.getpath (); Got ABC.
file directory = new file (".");
Directory.getcanonicalpath ();Got to be
C:\test
Directory.getabsolutepath ();Got to be
C:\test\.
Direcotry.getpath (); Got to be.
file directory = new file ("..");
Directory.getcanonicalpath ();Got to be
C +
Directory.getabsolutepath ();Got to be
C:\test\.
Direcotry.getpath (); What you get is that.
In addition: the string parameters in System.getproperty () are as follows:
system.getproperty () parameter Daquan
# 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.dirUser ' s current working directory
Java Gets the current path