Static member variables and paths of the File class

Overview of the File class:

java.io.File class
Abstract representation of file and directory path names.
Java closes the files and folders (directories) in the computer into a File class. We can use the File class to operate files and folders.
By default, the classes in the java.io package are always parsed according to the current user directory. Relative path name. This directory is specified by the system property user.dir and is usually the calling directory of the Java virtual machine.

We can use the method of the File class to
create a file/folder,
delete the file/folder,
get the file/folder,
judge the file/
folder, traverse the folder,
get the size of the file, and the
File class is a class that has nothing to do with the system, any operation The system can use the methods in this class

重点:记住这三个单词
    file:文件
    directory:文件夹/目录
    path:路径

Static member variables of the File class

public class Demo01File {
    
    
    public static void main(String[] args) {
    
    
        /*  static String pathSeparator 与系统有关的路径分隔符,为了方便,它被表示为一个字符串。
            static char pathSepartorChar 与系统有关的路径分隔符

            static String separator 与系统有关的默认分隔符,为了方便,它被表示为一个字符串。
            static char separatorChar 与系统有关的默认分隔符

            操作路径:路径不能写死了
            D:\Learn\Program.all\java.program\.idea  windows
            D:/Learn/Program.all/java.program/.idea  linux
            "D:"+File.separator+"Learn"+File.separator+"Program.all"+File.separator+"java.program"+File.separator+".idea"
        */
        String pathSeparator = File.pathSeparator;
        System.out.println(pathSeparator);  //路径分隔符 windows:分号;Linux:冒号:

        String separator = File.separator;
        System.out.println(separator);  //文件名称分隔符 Windows:反斜杠\ linux:正斜杠:/

    }
}

path

Absolute path: is a complete path. The path
starting with the drive letter (C:D:) is
D:\ProgramData\a.txt
C:\Users\Default\213.txt.
Relative path: is a simplified path.
Relative refers to Relative to the root directory of the current project (C:\Users\Default),
if you use the root directory of the current project, the path can be simplified to write
C:\Users\Default\213.txt -> simplified to: 213.txt (you can omit the project Root directory)
Note:
1. The path is not case sensitive
. 2. The file name separator in the path Windows uses backslashes, which are escape characters, and two backslashes represent a normal backslash.

Guess you like

Origin blog.csdn.net/weixin_44664432/article/details/108443229