首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从FileItem获取完整路径

如何从FileItem获取完整路径
EN

Stack Overflow用户
提问于 2017-11-01 17:51:05
回答 1查看 314关注 0票数 0

如何从FileItem获取完整路径并放入FileInputStream,似乎我只能getName。下面是我的代码,我试图上传文件和自动压缩到服务器。谢谢

代码语言:javascript
复制
DiskFileItemFactory fup = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fup);

List items = upload.parseRequest(req);
Iterator iter = items.iterator();

while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();                             
                if (!item.isFormField()) {

                File f = new File(Properties.get("dir") + File.separator + "test.zip");
                ZipOutputStream out = new ZipOutputStream(new FileOutputStream(f));
                ZipEntry e = new ZipEntry(flNm);
                out.putNextEntry(e);
                FileInputStream in = new FileInputStream((File) item);

                byte[] buffer = new byte[1024];
                int len;
                while ((len = in.read(buffer)) > 0) {
                    out.write(buffer, 0, len);
                }
                in.close();
                out.closeEntry();

                out.close();
                }
}
EN

回答 1

Stack Overflow用户

发布于 2017-11-01 17:54:40

您正在读取引用新创建的空临时文件的File对象。并将其写入到文件中。你确定这就是你想做的吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47052097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档