方法一览

image.png

获取文件信息

  1. import java.io.File;
  2. public class Main {
  3. public static void main(String[] args) {
  4. // 创建文件对象
  5. File file = new File("./create01.txt");
  6. // 获取文件名
  7. System.out.println(file.getName());
  8. // 获取文件绝对路径
  9. System.out.println(file.getAbsolutePath());
  10. // 获取路径
  11. System.out.println(file.getPath());
  12. // 获取父级目录
  13. System.out.println(file.getParent());
  14. // 获取文件大小
  15. System.out.println(file.length());
  16. }
  17. }