//文件存储路径 String savePath = "G:/Photo"; //创建文件路径 File dest =new File(savePath); //判断文件父目录是否已经存在,不存在则创建 if(!dest.exists()){ dest.mkdir(); } //把文件写到指定的路径 part.write(savePath + File.separator + fileName);
2.存在父级目录
String path = "D:/fileUpload/" + fileName; //输出文件的绝对路径 System.out.println("保存文件的绝对路径" + path + "\n"); //创建文件路径 File dest =new File(path); //判断文件是否已经存在 if(dest.exists()){ return "文件已经存在!!!!!!!!!!!!!!!!"; } //判断文件父目录是否已经存在,不存在则创建 if(!dest.getParentFile().exists()){ dest.getParentFile().mkdir(); }