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. 空指針在片段內創建片段時出現異常