Convert FileItem to File

25.7k Views Asked by At

I'm trying to upload a XML file (text.xml) using a simple upload html form, regulary read it as FileItem in the servlet and then get the ACTUAL file (text.xml) so i can print it, save it etc. Is there any educated way to do this simply? some people told me to use FileItem's property getInputStream.. is there any example somewhere? isn't there a shorter way?

thanks

1

There are 1 best solutions below

0
On

Just use FileItem#write() method, exactly as demonstrated in User Guide of Apache Commons FileUpload.

File file = new File("/path/to/text.xml");
fileItem.write(file);

That's all.

See also: