package com.sankuai.meituan.waimai.search.evaluate.util;
import java.io.*;
/**
* Created by slim-pc on 16/5/5.
*/
import java.util.zip.*;
public class ZipCompressor {
public static boolean ZipMultiFile(String[] filepaths ,String zippath) {
try {
File zipFile = new File(zippath);
InputStream input = null;
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
for(String filepath : filepaths) {
File file = new File(filepath);
input = new FileInputStream(file);
//zipOut.putNextEntry(new ZipEntry(file.getName() + File.separator + file.getName()));
zipOut.putNextEntry(new ZipEntry(File.separator + file.getName()));
int temp = 0;
while((temp = input.read()) != -1){
zipOut.write(temp);
}
input.close();
}
zipOut.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public static void ZipMultiFile(String filepath ,String zippath) {
try {
File file = new File(filepath);// 要被压缩的文件夹
File zipFile = new File(zippath);
InputStream input = null;
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
if(file.isDirectory()){
File[] files = file.listFiles();
for(int i = 0; i < files.length; ++i){
input = new FileInputStream(files[i]);
zipOut.putNextEntry(new ZipEntry(file.getName() + File.separator + files[i].getName()));
int temp = 0;
while((temp = input.read()) != -1){
zipOut.write(temp);
}
input.close();
}
}
zipOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String[] ss = new String[2];
ss[0] = "/Users/slim-pc/Downloads/1_1";
ss[1] = "/Users/slim-pc/Downloads/1_2";
String s = "/Users/slim-pc/Downloads/1.zip";
ZipMultiFile(ss, s);
}
}
import java.io.*;
/**
* Created by slim-pc on 16/5/5.
*/
import java.util.zip.*;
public class ZipCompressor {
public static boolean ZipMultiFile(String[] filepaths ,String zippath) {
try {
File zipFile = new File(zippath);
InputStream input = null;
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
for(String filepath : filepaths) {
File file = new File(filepath);
input = new FileInputStream(file);
//zipOut.putNextEntry(new ZipEntry(file.getName() + File.separator + file.getName()));
zipOut.putNextEntry(new ZipEntry(File.separator + file.getName()));
int temp = 0;
while((temp = input.read()) != -1){
zipOut.write(temp);
}
input.close();
}
zipOut.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public static void ZipMultiFile(String filepath ,String zippath) {
try {
File file = new File(filepath);// 要被压缩的文件夹
File zipFile = new File(zippath);
InputStream input = null;
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
if(file.isDirectory()){
File[] files = file.listFiles();
for(int i = 0; i < files.length; ++i){
input = new FileInputStream(files[i]);
zipOut.putNextEntry(new ZipEntry(file.getName() + File.separator + files[i].getName()));
int temp = 0;
while((temp = input.read()) != -1){
zipOut.write(temp);
}
input.close();
}
}
zipOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String[] ss = new String[2];
ss[0] = "/Users/slim-pc/Downloads/1_1";
ss[1] = "/Users/slim-pc/Downloads/1_2";
String s = "/Users/slim-pc/Downloads/1.zip";
ZipMultiFile(ss, s);
}
}