首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ZipOutputStream抱怨FileNotFoundException

ZipOutputStream抱怨FileNotFoundException
EN

Stack Overflow用户
提问于 2013-03-15 21:39:46
回答 2查看 626关注 0票数 0

new_file_name有点像2013-03-15-08:59:10_65.zip

代码语言:javascript
复制
 fileZip = new ZipOutputStream(new FileOutputStream(new File(new_file_name)));
    byte[] buffer = new byte[1024];
    try{
        for(String fileName:fileList)
        {
            FileInputStream in = null;
            try{
                File file = new File(fileName);
                ZipEntry ze = new ZipEntry(fileName);
                fileZip.putNextEntry(ze);
                in = new FileInputStream(file);
                int len = 0;
                while((len = in.read(buffer)) > 0) {
                    fileZip.write(buffer, 0, len);
                }
                fileZip.closeEntry();
                in.close();
            } catch (Exception e) {
                log(0, "Exception writing "+fileName+" to "+new_file_name+": "+e.toString());
        }

我得到了这个异常Exception writing to 2013-03-15-09:28:20_65.zip: java.io.FileNotFoundException: (No such file or directory)

该目录具有完全权限。我也看到了一个在文件夹中创建的文件,我也尝试了给getAbsolutePath(),仍然给了我同样的异常。

EN

回答 2

Stack Overflow用户

发布于 2013-03-15 21:45:54

我已经编写了一些实用方法来使用NIO.2 file API (该库是开源的)将目录复制到Zip文件或从Zip文件复制目录:

Maven:

代码语言:javascript
复制
<dependency>  
    <groupId>org.softsmithy.lib</groupId>  
    <artifactId>softsmithy-lib-core</artifactId>  
    <version>0.3</version>  
</dependency>  

教程:

http://softsmithy.sourceforge.net/lib/current/docs/tutorial/nio-file/index.html#AddZipResourceSample

接口名:CopyFileVisitor.copy

也许你会发现它很有用。

票数 1
EN

Stack Overflow用户

发布于 2013-03-15 21:44:44

我认为你不被允许在文件名中使用':',如果你使用"2013-03-15-08_59_10_65.zip“应该没问题。

好的..。不知何故,我设法找到相同的错误,当一个文件在fileList中不存在!

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

https://stackoverflow.com/questions/15433929

复制
相关文章

相似问题

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