文件上传问题,请高手帮忙看看
请高手帮忙看看,为什么上传的文件和PDF文件夹一重启就不见了,再谢麻烦改成永久保存的,谢谢
public String addPdf() throws
IOException{
String targetDirectory=ServletActionContext.getServletContext().getRealPath("/pdf");
String targetFileName=generateFileName(fileName);
File target=new File(targetDirectory,targetFileName);
FileUtils.copyFile(doc,target);
System.out.println(target.getName());
String str="update Employees as e set e.pdf=? where e.empId=?";
String str2=request.getParameter("empId");
String str4=request.getParameter("gaiyao");
String str1=","+str4+":pdf/"+targetFileName;
employeesbiz.update(str,str1,str2);
//String str3="from Employees as e where e.empId=?";
//Employees empdg=(Employees) employeesbiz.serch(str3,str2);
//session.put("empId", empdg);
request.setAttribute("empId", str2);
return "success";
}
------解决方案--------------------Java code
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(fileupload));//fileupload上传的文件流
String="/tmp"
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(path)));
byte[] buffer = new byte[1024];
int len;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);// 写入文件
}
------解决方案--------------------
流没有关闭。而且保存文件,最好不要保存到工程下,单独建立目录保存。
------解决方案--------------------