将FileItem转换为File [英] Convert FileItem to File

查看:2360
本文介绍了将FileItem转换为File的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用简单的上传html表单上传XML文件(text.xml),定期在servlet中将其作为FileItem读取,然后获取ACTUAL文件(text.xml)以便我可以打印它,保存它是否有任何受过良好教育的方式来做到这一点?有人告诉我使用FileItem的属性getInputStream ..有什么例子吗?是不是有更短的方式?

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?

谢谢

推荐答案

使用 FileItem#write() 方法,完全如 Apache Commons FileUpload 的nofollow noreferrer>用户指南。

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);

这就是全部。

  • How do I set the folder for storing file uploads using Commons FileUpload
  • How to upload files to server using JSP/Servlet?

这篇关于将FileItem转换为File的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆