poi 文件无法找到

Buhuishangdang 2009-07-03 11:42:22
最近做一项目,客户要求一上传excel功能,在网上找了一些资料,有了大概的做法.....

我用的struts做的上传,由于数据可能比较大,所以是先把excel压缩成zip进行上传,上传后再进行解压,解析excel的信息,然后插入库。下面是一些代码



ZipInputStream in = null;
List errors=null;
// FileInputStream(path+fileName));
try {
in = new ZipInputStream(new FileInputStream(path + "\\" + fileName));
ZipEntry entry = new ZipEntry(path + "\\" + fileName);
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file1 = new File(path + "\\" + entryName);
file1.mkdirs();
// System.out.println("创建文件夹" + entryName);
} else {
System.out.println(path + "\\" + entryName);
POIFSFileSystem poi = new POIFSFileSystem(new FileInputStream(path+"\\"+fileName)); HSSFWorkbook book = new HSSFWorkbook(poi);
}
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
in.closeEntry();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}



文件已经上传成功,而且接压缩也没有问题,路径是对的,可是在去取excel的时候出错了:


D:\work\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\JS\tmp\ko.zip
D:\work\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\JS\tmp\test.xls
java.io.FileNotFoundException: D:\work\projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\JS\tmp\test.xls (系统找不到指定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at ie.js.tyxxc.service.impl.TyxxcSiteDenizenServiceImpl.isQualified(TyxxcSiteDenizenServiceImpl.java:116)
at ie.js.tyxxc.service.impl.TyxxcSiteDenizenServiceImpl.upload(TyxxcSiteDenizenServiceImpl.java:81)
at ie.js.tyxxc.service.impl.TyxxcSiteDenizenServiceImpl$$FastClassByCGLIB$$c398d221.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:696)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:631)
at ie.js.tyxxc.service.impl.TyxxcSiteDenizenServiceImpl$$EnhancerByCGLIB$$4df71e08.upload(<generated>)
at ie.js.tyxxc.action.TyxxcSiteDenizenAction.parse(TyxxcSiteDenizenAction.java:259)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)


zip中的东西没有实际解压到硬盘中,是不是这个原因而拿不到啊??改怎么解决?
...全文
221 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Buhuishangdang 2009-07-06
  • 打赏
  • 举报
回复
没人解决。自己搞定了。。。。。。。。。。
其实问题就出现在这里,解压后的文件根本就没写道硬盘上,通过路径肯定是得不到的,所以用同一个流就ok 了。
ZipInputStream in = null;
List errors=null;
// FileInputStream(path+fileName));
try {
in = new ZipInputStream(new FileInputStream(path + "\\" + fileName));
ZipEntry entry = new ZipEntry(path + "\\" + fileName);
while ((entry = in.getNextEntry()) != null) {
String entryName = entry.getName();
if (entry.isDirectory()) {
File file1 = new File(path + "\\" + entryName);
file1.mkdirs();
// System.out.println("创建文件夹" + entryName);
} else {
System.out.println(path + "\\" + entryName);
POIFSFileSystem poi = new POIFSFileSystem(in);
HSSFWorkbook book = new HSSFWorkbook(poi);
}
}

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧