简体   繁体   English

如何使用Java在文件上传中获取本地磁盘文件路径? 如果是基于表单的Web应用程序...?

[英]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.

相关问题 是否可以使用Java在文件上传中获取文件本地系统路径? - is it possible to get file local system path in file upload using java? Java Web Application:如何获取所选文件的原始路径? - Java Web Application:how to get the original path of selected file? 如何设置文件路径以通过Java Web应用程序将文件保存在本地计算机中 - How to set file path to save a file in my local computer from java web application Java,使用磁盘上的路径打印文件 - Java, printing file using its path on disk 使用Java Web应用程序上载文件,但不使用Java Servlet - Upload file with java web application but not using Java servlet 使用多部分表单对上传图像进行改造,但未获取文件路径 - With retrofit upload image using multipart form but not get the path of the file Java-Java Web应用程序中文件的相对路径 - Java - Relative path of a file in a java web application 如何使用Java Web应用程序将文件上传到Google驱动器? - How to upload file to Google drive with java web application…? 如何在远程服务器上上传和部署 java web 应用程序(war 文件)? - How to upload and deploy java web application (war file) on remote server? 如何在Web应用程序的Java类中给出绝对的“文件路径”? - How to give absolute “file-path” in a java class of a web application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM