Java Gets the current path

Source: Internet
Author: User
Tags file separator

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

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.