package cn.meowrain.IO;
import java.io.File;
import java.io.IOException;
public class FileCreate {
public static void main(String[] args) {
FileCreate create = new FileCreate();
create.create01();
create.create02();
create.create03();
}
public void create01(){
String filePath = "d:\\test.txt";
File file = new File(filePath);
try {
file.createNewFile();
System.out.println("文件创建成功");
}catch (IOException e){
e.printStackTrace();
}
}
public void create02(){
File parent_file = new File("d:\\");
String fileName = "hello.txt";
File file = new File(parent_file,fileName);
try {
file.createNewFile();
System.out.println("创建成功");
} catch (IOException e){
e.printStackTrace();
}
}
public void create03(){
String parentPath = "f:\\";
String fileName = "new3.txt";
File file = new File(parentPath,fileName);
try{
file.createNewFile();
System.out.println("创建成功");
}
catch (IOException e){
e.printStackTrace();
}
}
}