【发布时间】:2016-06-15 18:50:13
【问题描述】:
我想上传文件并将它们保存到特定目录。我是文件概念的新手。当我从我的页面上传文件时,它们保存在另一个目录中(C:\Users\ROOTCP~1\AppData\Local\ Temp\multipartBody989135345617811478asTemporaryFile) 并且不在指定目录中。我无法设置它。请帮助我找到解决方案。提前感谢所有帮助。
public static Result uploadHoFormsByHeadOffice() throws Exception {
Logger.info("@C HoForms -->> uploadHoFormsByHeadOffice() -->> ");
final String basePath = System.getenv("INVOICE_HOME");
play.mvc.Http.MultipartFormData body = request().body()
.asMultipartFormData(); // get Form Body
StringBuffer fileNameString = new StringBuffer(); // to save file path
// in DB
String formType = body.asFormUrlEncoded().get("formType")[0];// get formType from select Box
FilePart upFile = body.getFile("hoFiles");//get the file details
String fileName = upFile.getFilename();//get the file name
String contentType = upFile.getContentType();
File file = upFile.getFile();
//fileName = StringUtils.substringAfterLast(fileName, ".");
// path to Upload Files
File ftemp= new File(basePath +"HeadOfficeForms\\"+formType+"");
//File ftemp = new File(basePath + "//HeadOfficeForms//" + formType);
File f1 = new File(ftemp.getAbsolutePath());// play
ftemp.mkdirs();
file.setWritable(true);
file.setReadable(true);
f1.setWritable(true);
f1.setReadable(true);
//HoForm.create(fileName, new Date(), formType);
Logger.info("@C HoForms -->> uploadHoFormsByHeadOffice() <<-- Redirecting to Upload Page for Head Office");
return redirect(routes.HoForms.showHoFormUploadPage());
}
}
我真的很困惑为什么上传的文件保存在这个(C:\Users\ROOTCP~1\AppData\Local\Temp\multipartBody989135345617811478asTemporaryFile)路径中。
【问题讨论】:
-
INVOICE_HOME的值是多少? -
基本路径的值为:D:\
标签: java file-upload playframework-2.0