/** * Created by IntelliJ IDEA. * User: The Hien * Date: Sep 22, 2009 * Time: 2:50:10 PM */ public class ZipFolder { public static void main(String arg[]) throws Exception { int dayBefore = 1;
String srcFolder = "C:\\Documents and Settings\\The Hien\\Desktop\\LogXS";
/*Tim thu muc ngay hom truoc se la: 102009/18102009*/
DateFormat dateFormat = new SimpleDateFormat("/MMyyyy/ddMMyyyy"); srcFolder = srcFolder + dateFormat.format(calendar.getTime());
String destZipFile = srcFolder + ".zip";
File file = new File(srcFolder); if (file.exists() && file.isDirectory()) ;
zipFolder(srcFolder, destZipFile); (new SendFile()).fileTranfer(); DelFolder.deleteDir(new File(srcFolder));
/* Nen folder 6/9/2009-> Path folder: 092009/06092009 Kiem tra folder ton tai , neu ton tai thi zip thu muc 06092009-> 06092009.zip Gui len ftp server vao thu muc [desdir]/092009/ */ }
static public void zipFolder(String srcFolder, String destZipFile) throws Exception { ZipOutputStream zip = null; FileOutputStream fileWriter = null; boolean ziped = false; try { fileWriter = new FileOutputStream(destZipFile); zip = new ZipOutputStream(fileWriter);
File folder = new File(scrFile); if ((folder.isDirectory())) { addFolderToZip(Path, scrFile, zip); } else {
byte[] buffer = new byte[1024]; int len; FileInputStream in = null; try { in = new FileInputStream(scrFile); zip.putNextEntry(new ZipEntry(Path + "/" + folder.getName()));
/* putNextEntry(new ZipEntry(filesToZip)) là m?t ph??ng th?c c?a l?p ZipOutputStream dùng ?? ??a vào t?ng file m?t ?? nén l?i.*/