当我尝试保存/更新文件时,我收到以下错误
1 /错误1:当我尝试更新我的用户信息时,会出现此问题
Part filePart = request.getPart("image");
InputStream inputStream = null; // input stream of the upload file
if (filePart != null) {
// prints out some information for debugging
System.out.println(filePart.getName());
System.out.println(filePart.getSize());
System.out.println(filePart.getContentType());
inputStream = filePart.getInputStream();
}
// String image = request.getParameter("image");
CandidatDAO dao = new CandidatDAO();
Part part = request.getPart("image");
String filename = extractFileName(part);
String save_path = File.separator +filename ;
File filesaveDir = new File(save_path);
part.write(save_path+File.separator);
String filePath = save_path+File.separator+filename;
dao.Update(new Candidat(id,nom,prenom,naiss,cin,sexe,nat,email,adresse,tel, (Blob) inputStream,login,mdp));
ArrayList list = dao.FindAll();
ServletContext cn = request.getServletContext();
cn.setAttribute("liste", list);
response.sendRedirect("ListeCandidat.jsp");
2 /错误2:当我试图保存文件时
Part part = request.getPart("image");
String filename = extractFileName(part);
String save_path = "D:\\Examtp(2)\\Examtp\\web\\imagesF\\"+File.separator +filename;
// String save_path = "D:\\Master2017-2018\\JEE\\TP\\Examtp\\web\\imagesF\\"+File.separator +filename ;
File filesaveDir = new File(save_path);
part.write(save_path+File.separator);
String filePath = save_path+File.separator+filename;
FormateurDAO dao = new FormateurDAO();
dao.Add(new Formateur(nom,prenom,naiss,cin,sexe,nat,email,adresse,tel,filename,login,mdp));
// ArrayList list = dao.FindAll();
ServletContext cn = request.getServletContext();
cn.setAttribute("cin", cin);
response.sendRedirect("AjouterDiplome.jsp");
答案 0 :(得分:0)
fileSaveDir.mkdirs()
。 File fileSaveDir = new File(...)
本身在磁盘上没有任何作用。