跳转到内容
Jsonq's Blog
返回

二、Java SE 高级

所有笔记内容基于网络上的黑马视频课程自行整理,如有侵权,请联系删除…

Table of contents

Open Table of contents

File

  1. File 创建文件,如果路径是相对路径,那就会在当前运行项目的根目录下查找或创建
File file = new File("E:\\A.txt"); // 文件路径和文件夹路径都支持
File file1 = new File("E:\\", "A.txt");
File file2 = new File(new File("E\\"), "A.txt");

System.out.println(file.exists()); // 是否存在

// 创建文件,相对路径,在当前项目根目录创建
File file3 = new File("A.txt");
try {
    boolean newFile = file3.createNewFile();
    System.out.println(newFile); // true
    System.out.println(file3.getAbsoluteFile()); // F:\myself\java-learn\java-01\java-01\A.txt
} catch (IOException e) {
    throw new RuntimeException(e);
}
  1. File 常用 API

常用 API / IO



上一篇
一、Java SE 基础