About path separators: The difference between forward slash/, backslash \, double backslash \ \ \

Source: Internet
Author: User
Tags escape quotes

1. These symbols have different meanings under different systems:

Double slash: Delimiter between protocol and host name (e.g. http://localhost:8080)
/single Slash: Directory schema separators in Windows or on the Web or UNIX kernel
\ backslash: The delimiter of the directory structure in Windows, the forward slash is also available.
\ \ Double backslash: The first item in Windows that represents an absolute address, such as following the IP address, is the network share resource that needs to open the IP address.

2. Questions about the spacing between directories are preceded by a forward slash (/) or a backslash (\).

1) in the UNIX environment, the delimiter in the directory is a forward slash/.

2) on the Windows platform, the spacers in the directory are either forward slash/and backslash \ All.

3) In a Java program, the delimiter in the directory can be a forward slash/. The backslash \ denotes the escape character, so if you need to use the backslash \ as the directory delimiter on the Windows platform in a Java program, you must have a double backslash \ \.

That is, the directory spacing character is either a slash/or double backslash \ \.

3. Analyze the backslash \ \
The change is more of the backslash, the backslash in C (and most of the programming language) is the escape character, that is, after the character will have different meanings, such as \ n means carriage return, such as
In Perl, $x represents a variable, and \ $x is not a variable. As for \ \ is the back of the \ escaped, at this time after the \ is not an escape character,
Instead, the \ character itself, for example:
printf ("\\n");
The print is \ n, not a carriage return.
You just have to remember that you'll be able to escape the following characters, like
printf ("\\\");
The result is a compilation error, because the first two \ \ is the \ character itself, and the third \ will escape the back ", so that a quotation mark is missing, resulting in a compilation error.
\ Escape quotes in a lot of places, mainly to include quotes in the string, such as:
printf ("Hello \" world\ "\ n");

Example: Now in the servlet program want to get a Test.doc file (in the root directory of the current WEB application/web-inf/files folder) output stream:

Of course, it could be here, too.

Or is

To print filename, you can get E:\apache-tomcat-8.0.37\webapps\20161028-FileUpLoad\WEB-INF\files\test.doc.

Then write to OutputStream, enter the E:\apache-tomcat-8.0.37\webapps\20161028-FileUpLoad\WEB-INF\files directory, You will see that there is one more file: Test.doc.

At the same time, this means: get the absolute path (the deployed path, not the pre-deployment path) of one of the current Web application's files on the server by Getrealpath.

About path separators: The difference between forward slash/, backslash \, double backslash \ \ \

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.