62,621
社区成员
发帖
与我相关
我的任务
分享package test;
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String []args){
File directory = new File("D:\\demosun");
if(!directory.exists()){
directory.mkdirs();
}
File file = new File("D:\\demosun\\demosu.txt");
try{
if(!file.exists()){
file.createNewFile();
}
}
catch(IOException e){
e.printStackTrace();
}
if(file.exists()){
System.out.println("文件夹及文件创建成功");
}
}
}
public static void main(String[] args) throws IOException {
File file = new File("d:/demosun/demosu.txt");
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
if(!file.exists())
file.createNewFile();
}
File file = new File("D:\\demosun");
if (!file.exists()){
file.mkdirs() ;
}
file = new File("D:\\demosun\\demosu.txt") ;
if (!file.exists()){
bool b = file.createNewFile();
if (b){
System.out.println("创建成功。") ;
}
}