package file;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
public class FileCreate {
public static void main(String[] args) {
new FileCreate().create01();
new FileCreate().create02();
new FileCreate().create03();
}
public void create01(){
String filePath = "e:\\A.txt";
File file = new File(filePath);
try {
file.createNewFile();
System.out.println("文件创建成功");
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public void create02(){
File parentFile = new File("e:\\");
String fileName = "B.txt";
File file1 = new File(parentFile, fileName);
try {
file1.createNewFile();
System.out.println("文件创建成功");
} catch (IOException e) {
e.printStackTrace();
}
}
public void create03(){
String parentFile = "E:\\";
String fileName = "C.txt";
File file = new File(parentFile,fileName);
try {
file.createNewFile();
System.out.println("文件创建成功");
} catch (IOException e) {
e.printStackTrace();
}
}
}
|