java.io.FileNotFoundException :(拒绝访问)和Cast问题

时间:2018-01-28 23:33:19

标签: java jdbc java-io

当我尝试保存/更新文件时,我收到以下错误

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");

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

  1. 保存文件前需要fileSaveDir.mkdirs()File fileSaveDir = new File(...)本身在磁盘上没有任何作用。
  2. 不要在一个帖子中提出多个问题。