另一方面,判断文件是否存在,如果不存在则制作
文件文件=new file (d : (test.txt );
if (! file.exists () }
try {
file.createNewFile (;
}catch(ioexceptione ) {
e .打印堆栈跟踪(;
}
System.out.println (文件已创建);
} else {
System.out.println (文件已经存在);
}
二、判断文件夹是否存在,如果不存在则创建
filefolder=new file (d :\ test1\ test2);
if (! folder.exists ()! folder.isDirectory (
folder.mkdirs (;
System.out.println ('创建文件夹');
} else {
System.out.println (“文件夹已存在”);
}
原文链接: https://blog.csdn.net/ITM yhome 1990/article/details/51243997