// 设置保存上传文件的目录
String uploadDir = getServletContext().getRealPath("/") + "upload"; // 获得服务器的绝对路径
if(uploadDir == null) {
out.print("无法访问存储目录!");
return;
}
File fUploadDir = new File(uploadDir);
if(!fUploadDir.exists()) {
if(!fUploadDir.mkdir()) {
out.println("无法创建存储目录!");
return;
}
}
这段已经为你创建了这个目录 不需要手动去创建
String uploadDir = getServletContext().getRealPath("/") + "upload"; // 获得服务器的绝对路径
if(uploadDir == null) {
out.print("无法访问存储目录!");
return;
}
File fUploadDir = new File(uploadDir);
if(!fUploadDir.exists()) {
if(!fUploadDir.mkdir()) {
out.println("无法创建存储目录!");
return;
}
}
这段已经为你创建了这个目录 不需要手动去创建
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
前面的路径用uploadDir 你创建保存文件夹的路径FileOutputStream fos = new FileOutputStream(uploadDir+File.separator +
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
如果存在指定的地方String uploadpath=“E:\\”;FileOutputStream fos = new FileOutputStream(uploadpath +
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
fos.write(*,0,*);//*号你自己改吧
如果存在指定的地方String uploadpath=“E:\\”; FileOutputStream fos = new FileOutputStream(uploadpath +
System.currentTimeMillis() +
fileName.substring(fileName.lastIndexOf("."),fileName.length()));
fos.write(*,0,*);//*号你自己改吧