2

我们可以FileItem使用 Java 从给定的文件名和文件位置创建对象吗?如果我们使用 commons-fileupload jar,我们可以使用 jsp/html 上传文件,并在解析请求时在 servlet 中获取List<FileItem>. 但是我想使用纯 java 进行文件上传,我想在其中FileItem手动创建对象(我不想使用byte[]数组来存储文件)。那么有什么方法可以FileItem手动创建对象吗?

4

1 回答 1

1

Yes, you can.

Use the DiskFileItemFactory like this:

DiskFileItemFactory factory = new DiskFileItemFactory();
FileItem fi = factory.createItem("formFieldName", "application/zip", false,
    "/var/temp/somefile.zip");

Obviously use content type and other parameters appropriate to your case.

于 2014-07-16T06:52:37.490 回答