Home > Back-end >  Generated compressed file, found a size of 0, the compressed size is 2 empty file
Generated compressed file, found a size of 0, the compressed size is 2 empty file

Time:10-24

As title, detailed see screenshot:


Extract out later this empty file is missing, excuse me each big shrimp: what is this? How to solve?

PS:
Some compression on the software that is the case, as shown in figure:


Attach a snippet:
 
Try {
ZipOutputStream out=new ZipOutputStream (new FileOutputStream (strZipPath));
//need to download multiple files at the same time
//traverse folders, assembly file directory
Set Keys.=folderMap keySet ();
For (Integer key: keys) {
HashMap ValueItem=folderMap. Get (key);
//absolute path to the file name (format:/LJZSG/fastdfs/file/data/00/06/wKgD91vHCPuAJdNzAAEn6ED7yKg207. JPG)
String urlPath=valueItem. Get (" url ");
//the full path to the file name (format: test \ \ 2 2. JPG)
String fullPathName=valueItem. Get (" fullPathName ");

If (FileType. FILE. GetValue (). The toString (). The equals (valueItem. Get (" type "))) {//type of the FILE, then download
if (null !=urlPath & amp; & !" ". The equals (urlPath)
& & Null!=fullPathName & amp; & !" ". The equals (fullPathName)) {
//Java. IO. File f=new Java. IO. The File (absolutePathName);
//a FileInputStream fis=new FileInputStream (f);
BufferedInputStream in=dfsClient. DownLoad (urlPath);
Out. PutNextEntry (new ZipEntry (fullPathName));
//set up a character encoding in the compressed file, or it will become garbled
Out. SetEncoding (" GBK ");
Int len.
//read the content of the need to download the file, packaged into zip file
While ((len=in. Read (buffer)) & gt; 0 {
Out. Write (buffer, 0, len);
}
Out. CloseEntry ();
in.close();
}

} else if (FileType. DEMAND_FOLDER. GetValue (), toString (). The equals (valueItem. Get (" type "))
| | FileType. DEMAND_REFERENCE_SUB_FOLDER. GetValue (). The toString (). The equals (valueItem. Get (" type "))
| | FileType. INTERPOSE_REFERENCE_SUB_FOLDER. GetValue (). The toString (). The equals (valueItem. Get (" type "))
| | FileType. VALIDATE_REFERENCE_SUB_FOLDER. GetValue (). The toString (). The equals (valueItem. Get (" type "))
| | FileType. OTHER_FOLDER. GetValue (). The toString (). The equals (valueItem. Get (" type "))) {//type to folder, then the packaging empty folder
if (null !=fullPathName & amp; & !" ". The equals (fullPathName)) {
Out. PutNextEntry (new ZipEntry (fullPathName + Java. IO. File. The separator));
//set up a character encoding in the compressed file, or it will become garbled
Out. SetEncoding (" GBK ");
Out. CloseEntry ();
}
}
}
Out. The close ();
Logger. The info (download "start");
Logger. The info (" fileNameNoSufix="+ FileUtil. GetFileNameNoEx (filename));
DownloadFile (request, response, strZipPath, FileUtil getFileNameNoEx (filename) + ". Zip ");
Logger. The info (" download end ");
Java. IO. File temp=new Java IO. The File (strZipPath);
{if (temp. The exists ())
Temp. The delete ();
Logger. The info (" delete the zip file. ");
}
} the catch (Exception e) {
Logger. Error (ReturnCode ERR_DOWNLOAD_FAILED + "", e);
}

CodePudding user response:

Meet the same problem not clear why

CodePudding user response:

Found two problems:
1. You should use UTF8 encoding is better, this as file and directory name, are less likely to produce noise,
2. FolderMap. KeySet () returns a collection of the inside of the content is unordered, how do you ensure storage directory first, and then store files in the directory? Try out the effect of row a sequence,
  • Related