package com.fanjia.practice;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
/**
* Created by FanJia on 2020/8/16 9:35
*/
public class Demo02 {
@Test
public void test1() throws IOException {
File file = new File("a.txt");
file.createNewFile();
System.out.println(file.length());
System.out.println(file.exists());
System.out.println(file.isFile());
System.out.println(file.isDirectory());
System.out.println(file.getName());
System.out.println(file.getParent());
System.out.println(file.getAbsoluteFile());
System.out.println(file.getAbsolutePath());
}
@Test
public void test2() throws IOException {
File file = new File("e:/y700/a");
file.mkdir();
File file1 = new File("e:/y700/a/b/c");
file1.mkdirs();
File file2 = new File("e:/y700/a/a.txt");
file2.createNewFile();
for (String s :file.list()){
System.out.println(s);
}
for (File f1 : file.listFiles()){
System.out.println(f1.getAbsolutePath());
}
}
}
File类的基本用法
于 2020-08-16 10:39:33 首次发布