通过一个if判断,如果文件不存在,判断其父目录是否存在,如果不存在一同创建操作
File inputFile = new File(filePath + fileName);
if (!inputFile.exists() // 判断文件是否存在
&& (inputFile.getParentFile().exists() || inputFile.getParentFile().mkdirs()) // 判断父目录是否存在,不存在即创建
&& !inputFile.createNewFile()) { // 创建文件
throw new IOException("Input txt file create failed");
}