创建文件
public static void main(String[] args) throws IOException {
File file = new File("D:\\io\\myTest.txt"); //文件地址
if(file.exists()){ //文件已经存在
System.out.println("文件已经存在");
System.exit(-1);
}
file.getParentFile().mkdir(); //创建父文件夹
try{
file.createNewFile(); //创建文件
}catch (IOException e){
e.printStackTrace();
System.exit(-1);
}
System.out.println("文件已经创建成功");
System.out.println(file.getAbsolutePath());
}

浙公网安备 33010602011771号