new_file_name有点像2013-03-15-08:59:10_65.zip
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(),仍然给了我同样的异常。
发布于 2013-03-15 21:45:54
我已经编写了一些实用方法来使用NIO.2 file API (该库是开源的)将目录复制到Zip文件或从Zip文件复制目录:
Maven:
<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
也许你会发现它很有用。
发布于 2013-03-15 21:44:44
我认为你不被允许在文件名中使用':',如果你使用"2013-03-15-08_59_10_65.zip“应该没问题。
好的..。不知何故,我设法找到相同的错误,当一个文件在fileList中不存在!
https://stackoverflow.com/questions/15433929
复制相似问题