0
A
回答
0
java.util.zipException:太短,拉链意味着你的邮编是无效的。请检查您是否正在创建有效的邮编。
你可以找到Example
我已经验证和下面的代码工作。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
public class CreateZipFileDirectory {
public static void main(String args[])
{
try
{
String zipFile = "Path where zip needs to be creaetd e.g.zipdemo.zip";
String sourceDirectory = "directory which contains files.";
//create byte buffer
byte[] buffer = new byte[1024];
/*
* To create a zip file, use
*
* ZipOutputStream(OutputStream out)
* constructor of ZipOutputStream class.
*
*/
//create object of FileOutputStream
FileOutputStream fout = new FileOutputStream(zipFile);
//create object of ZipOutputStream from FileOutputStream
ZipOutputStream zout = new ZipOutputStream(fout);
//create File object from directory name
File dir = new File(sourceDirectory);
//check to see if this directory exists
if(!dir.isDirectory())
{
System.out.println(sourceDirectory + " is not a directory");
}
else
{
File[] files = dir.listFiles();
for(int i=0; i < files.length ; i++)
{
System.out.println("Adding " + files[i].getName());
//create object of FileInputStream for source file
FileInputStream fin = new FileInputStream(files[i]);
/*
* To begin writing ZipEntry in the zip file, use
*
* void putNextEntry(ZipEntry entry)
* method of ZipOutputStream class.
*
* This method begins writing a new Zip entry to
* the zip file and positions the stream to the start
* of the entry data.
*/
zout.putNextEntry(new ZipEntry(files[i].getName()));
/*
* After creating entry in the zip file, actually
* write the file.
*/
int length;
while((length = fin.read(buffer)) > 0)
{
zout.write(buffer, 0, length);
}
/*
* After writing the file to ZipOutputStream, use
*
* void closeEntry() method of ZipOutputStream class to
* close the current entry and position the stream to
* write the next entry.
*/
zout.closeEntry();
//close the InputStream
fin.close();
}
}
//close the ZipOutputStream
zout.close();
System.out.println("Zip file has been created!");
}
catch(IOException ioe)
{
System.out.println("IOException :" + ioe);
}
}
}
/*
Output of this program would be
Adding nonav.log
Adding ospreg.exe
Adding servers.ini
Adding setupisam.log
Adding sourceFile1.doc
Adding sourceFile2.doc
Zip file has been created!
*/
0
看看在readCentralDir()梅索德,你将不得不采取更深入地了解代码,但总体看来这个异常被抛出,一旦该文件是太短成为一个ZIP文件。
如下因素代码行(mRaf是随机访问文件):
long scanOffset = mRaf.length() - ENDHDR;
if (scanOffset < 0) {
throw new ZipException("too short to be Zip");
}
相关问题
- 1. 创建zip文件时出现异常错误
- 2. 创建表时出现休眠异常
- 3. 'java.lang.NoSuchFieldError:ignoreMethodBodies'创建AST时出现异常
- 4. 创建NSArray时出现异常
- 5. 创建关系时出现Neo4j异常
- 6. 创建collectionViewCell时出现异常
- 7. 在MonoDevelop中创建新的Iphone/Ipad窗口时出现异常
- 8. 在RIA中创建新实体时出现异常
- 9. java:Zip异常无效代码长度?
- 10. Powershell:创建并抛出新的异常
- 11. IIS - 创建新网站抛出异常
- 12. 空指针创建新模型或重新导入模型时出现异常
- 13. 使用java创建邻接列表时出现异常的异常
- 14. 尝试在EJB中创建计时器时出现异常
- 15. 添加新路线时出现异常
- 16. iOS:CoreData更新数据时出现异常
- 17. 更新Maven项目时出现异常?
- 18. 退出时出现异常
- 19. 构建Workitem商店时出现异常
- 20. 尝试创建新的任务调度程序任务时出现异常
- 21. 使用EF 6创建新迁移时出现未处理的异常
- 22. Java - DocumentBuilder在创建时抛出异常
- 23. 创建新的rails项目在安装json时抛出异常
- 24. 创建索引时出现异常 - Spring Data MongoDB
- 25. 从Asciidoctor创建PDF文件时出现异常
- 26. 创建Apache Tiles简单应用程序时出现异常
- 27. 使用initWithRelationship创建RKConnectionDescription时出现异常:属性:
- 28. Java ME:创建图像时出现问题。 IOException异常
- 29. 空指针创建2D选取器时出现异常
- 30. 空指针在片段内创建片段时出现异常