Absolute path relative path problem under Java File Linux windows

Source: Internet
Author: User

Objective

Current project directory

Windows for E:\project\testpro\

Linux for /project/testpro/

Obtaining an absolute path condition in the Windows environment

Use A/B/C as the path to get the absolute path: new File ("a/b/c"). GetAbsolutePath ()

The resulting path is E:\project\testpro\sspt-sppt\a\b\c

Use the/A/B/C path to get the absolute path to the new File ("/a/b/c"). GetAbsolutePath ()

It gets the path to E:\a\b\c ,

The difference lies in whether or not the directory was added before /

In Linux, the identity is the root directory.

Under window, it is replaced with a:\, b:\, c \, D:\ And so on, the selection of the drive letter is the standard of the drive letter of the item in Windows, and if the item is in a directory of the E drive letter, the selected drive letter is e:\.

Obtaining an absolute path condition in a Linux environment

Use A/B/C as the path to get the absolute path: new File ("a/b/c"). GetAbsolutePath ()

The resulting path is /project/testpro/sspt-sppt/a/b/c

Use the/A/B/C path to get the absolute path to the new File ("/a/b/c"). GetAbsolutePath ()

The resulting path is /a/b/c

Absolute path relative path problem under Java File Linux Windows

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.