58,454
社区成员
发帖
与我相关
我的任务
分享
//创建指定文件
private static void createFile(String _path, String _filename) {
String filepath = _path + "\\"+ _filename;//设置指定路径
File file = new File(filepath);
//当目录不存在时
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();//创建文件夹路径
}
//当文件不存在时
if (!file.exists()) {
try {
file.createNewFile();//创建指定文件
} catch (IOException e) {
System.err.println("创建 " + file + " 失败!");
}
}
}