IO 判断文件夹或者文件是否存在 不存在创建一个
import java.io.File; import java.io.IOException; public class IO_Createfile { public static void main(String[] args) throws IOException{ String strPath = "C:\\a\\aa\\aaa.txt"; File file = new File(strPath); if(!file.getParentFile().exists()){//判断文件夹在不在 file.getParentFile().mkdirs();//文件夹不在 创建文件夹 }if(!file.exists()){ //判断文件是否存在 不存在创建一个文件 file.createNewFile(); } } }
浙公网安备 33010602011771号