[英]How to get local disk file path in file upload using java? If it is form based web application…?
I am using MultipartFile to upload file by using multipartFile.transferTo(new java.io.File(saveDirectory,fileName));
我正在使用MultipartFile通过使用multipartFile.transferTo(new java.io.File(saveDirectory,fileName));
来上传文件multipartFile.transferTo(new java.io.File(saveDirectory,fileName));
. 。 How MultipartFile getting file path. MultipartFile如何获取文件路径。 In file upload we will get only file name. 在文件上传中,我们将仅获得文件名。
My code is: 我的代码是:
if (null != files && files.size() > 0) {
for (MultipartFile multipartFile : files) {
fileName = multipartFile.getOriginalFilename();
multipartFile.transferTo(new java.io.File(saveDirectory, fileName));
System.out.println("kkkkkkkkk" + fileName);
nameoffile = fileName;
fileNames.add(fileName);
//Handle file content - multipartFile.getInputStream()
}
}
import com.oreilly.servlet.MultipartRequest;
您可以使用MultipartRequest m=new MultipartRequest(request,"d:/new");
MultipartFile.getOriginalFilename
may contain path information from the client filesystem depending on the browser you are using. MultipartFile.getOriginalFilename
可能包含来自客户端文件系统的路径信息,具体取决于您使用的浏览器。 Most browsers like Firefox and Chrome will include include filename without path information. 诸如Firefox和Chrome之类的大多数浏览器将包括不带路径信息的文件名。 IE at one time did include the complete path information but not sure if that's still true with newer versions of IE. IE一次确实包含了完整的路径信息,但不确定新版本的IE是否仍然正确。
For more information, see the MultipartFile reference documentation . 有关更多信息,请参见MultipartFile参考文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.