java.io.File类中分隔符区别


1、separator
File.separator是系统默认的文件分隔符号,在UNIX系统上,这个字段的值是'/';在Microsoft Windows系统上,它是''。
类型:String

2、separatorChar
与系统有关的默认名称分隔符。此字段包含系统属性File.separator值的第一个字符。
类型:char

3、pathSeparatorChar
与系统有关的路径分隔符。此字段被初始为包含系统属性File.pathSeparator值的第一个字符。
类型:char

4、pathSeparator
与系统有关的路径分隔符。此字段被初始为包含系统属性File.pathSeparator值的第一个字符。此字符用于分隔以路径列表形式给定的文件序列中的文件名。在UNIX系统上,此字段为':';在Microsoft Windows 系统上,它为';'。
类型:String

下面是源码:


    /**
     * The system-dependent default name-separator character.  This field is
     * initialized to contain the first character of the value of the system
     * property file.separator.  On UNIX systems the value of this
     * field is '/'; on Microsoft Windows systems it is '\\'.
     *
     * @see     java.lang.System#getProperty(java.lang.String)
     */
    public static final char separatorChar = fs.getSeparator();

    /**
     * The system-dependent default name-separator character, represented as a
     * string for convenience.  This string contains a single character, namely
     * {@link #separatorChar}.
     */
    public static final String separator = "" + separatorChar;

    /**
     * The system-dependent path-separator character.  This field is
     * initialized to contain the first character of the value of the system
     * property path.separator.  This character is used to
     * separate filenames in a sequence of files given as a path list.
     * On UNIX systems, this character is ':'; on Microsoft Windows systems it
     * is ';'.
     *
     * @see     java.lang.System#getProperty(java.lang.String)
     */
    public static final char pathSeparatorChar = fs.getPathSeparator();

    /**
     * The system-dependent path-separator character, represented as a string
     * for convenience.  This string contains a single character, namely
     * {@link #pathSeparatorChar}.
     */
    public static final String pathSeparator = "" + pathSeparatorChar;