Reputation: 1635
I have making zip file using java. hence, i had face a small problem. Execute files(*.sh and binary files) are compressed is not properly with his file permissions. pls find the following code for make zip
public static void makeZip(String compressDirPath, String zipName, String outputLoc)
throws java.io.IOException
{
if(outputLoc.equals("") || outputLoc == null) outputLoc = ".";
File compressDir = new File(compressDirPath);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outputLoc+"/"+zipName));
compress(compressDir, compressDir, zos);
zos.close();
}
private static void compress(File compressDir, File base, ZipOutputStream zos) throws java.io.IOException
{
File[] files = compressDir.listFiles();
byte[] buffer = new byte[18024];
int read = 0;
for (int i = 0, n = files.length; i < n; i++) {
if (files[i].isDirectory()) {
compress(files[i], base, zos);
} else {
FileInputStream in = new FileInputStream(files[i]);
ZipEntry entry = new ZipEntry(files[i].getPath().substring(base.getPath().length() + 1));
zos.putNextEntry(entry);
while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); }
in.close();
}
}
}
When i have unzip the zipped file, execute files create by normal file. How can i solve this problem?
Upvotes: 1
Views: 455