Java手册

separatorChar

public static final char separatorChar
与系统有关的默认名称分隔符。此字段被初始化为包含系统属性 file.separator 值的第一个字符。在 UNIX 系统上,此字段的值为 '/';在 Microsoft Windows 系统上,它为 '\\'

 

另请参见:
System.getProperty(java.lang.String)
import java.io.File;

public class FileDemo5 {

    public static void main(String[] args) {

        // 在Windows中,分隔目录用的\
        // 在Linux中,分隔目录用的/
        // 在Windows中,分隔路径用的;
        // 在Linux中,分隔路径用的:
        // pathSeparatorChar 代表 :
        // separatorChar 代表 /
        File file = new File("E:" + File.separatorChar + "aaa.txt");

        // 获取父路径
        System.out.println(file.getParent());
        System.out.println(file.getName());

        // 获取绝对路径
        System.out.println(file.getAbsolutePath());
        // 获取路径
        System.out.println(file.getPath());

    }

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-12-31
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
猜你喜欢
  • 2021-08-13
  • 2022-01-09
  • 2021-11-30
  • 2021-04-06
  • 2021-12-30
  • 2022-12-23
  • 2021-10-09
相关资源
相似解决方案