File file = new File("D:\002\" + fileName + ".docx"); if(!file.getParentFile().exists()){ file.getParentFile().mkdir(); } if(!file.exists()){ boolean newFile = file.createNewFile(); }