Can We Create Fileitem Object from File Name and Location?
Can We Create Fileitem Object from Given File Name and File Location Using Java? If We Use Commons-Fileupload Jar We Can Upload File Using Jsp/Html and in...
Can we create FileItem object from given file name and file location using Java?
If we use commons-fileupload jar we can upload file using jsp/html and in servlet on parsing request we will get List<FileItem>. But I want to do file upload using plain java where I want to create FileItem object manually (I don't want to use byte[] array to store the file). So is there any way to create FileItem object manually?
1 Answer
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.