Slash and backslash
Forward slash, slash, also known as the left, is the symbol "/"
;
Backslash, also known as forward slashes, symbols are "\"
.
In the Unix/Linux
separator, the positive use of the inclined path "/"
, such as "cd /home/java"
;
In Windows
the path separated using a backslash "\"
, for example "F:\yihong_\book"
.
I developed in Windows
the platform, the Java
configuration file in the file are used in Road King "\\"
, and the project is deployed Linux
on, all files are used in Road King "/"
.
Escape character
Windows
I copied the F-address “F:\yihong_\book”
and paste it into a Java program, it will automatically become “F:\\yihong_\\book”
. This time the escape occurred, this operation is done automatically idea.
String path = "F:\\yihong_\\book";
correct
String path = "F:\yihong_\book";
Incorrect
In the java code development \
on behalf of the escape character.
Java
The escape character \
escaped not a need to escape, anything can escape, escape it only supports it:\b
\t
\n
\f
\r
\"
\'
\\
Absolute and relative paths
It indicates that the file path can be divided into absolute and relative paths.
Windows
Absolute path: drive letter, such as startF:\yihong_\book
Windows
relative path:
.
It refers to the current directory
..
It refers to the parent directory of the current directory
./book
It represents the current directory book
folder
/book
The letter represents the current book
folder
Linux
Absolute path: to root
the root directory path / beginning of such /
representation root
root directory
Linux
relative path:
./
It refers to the current directory
../
It refers to the parent directory of the current directory
.
It represents the current directory, ..
on behalf of the parent directory.
Use File.seperator
splicing file path
String fileSeperator = File.separator;
File.separator
It will use the correct file delimiter character depending on the operating system.
eg:
String dirName = FilenameUtils.getBaseName(parentStack.getFileName()) + File.separator + parentStack.getMethodName() + File.separator;
Java common system and method for obtaining path
// 分隔符
String fileSeperator = File.separator;
// 用户主目录
String userHome = System.getproperties().getProperty("user.home");
// Java实时运行环境的安装目录
String javaPath = System.getproperties().getProperty("java.home");
// 操作系统名称
String osName = System.getproperties().getProperty("os.name");
// 当前用户程序所在目录
String userDir = System.getproperties().getProperty("user.dir");
// JDK的安装目录
String jdkDir = System.getproperties().getProperty("java.ext.dirs");