1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| package Day2.text1;
import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream;
public class demol25 { public static void main(String[] args) throws IOException { File s0=new File("D:\\Javawork\\ddd\\aaa"); File s1=s0.getParentFile(); File s2=new File(s1,s0.getName()+".zip"); System.out.println(s2); ZipOutputStream s3=new ZipOutputStream(new FileOutputStream(s2)); tozip(s0,s3, s0.getName()); s3.close(); }
public static void tozip(File s0,ZipOutputStream s3,String name) throws IOException { File[] s4 = s0.listFiles(); for (File s5 : s4) { if(s5.isFile()){ ZipEntry s6=new ZipEntry(name+"\\"+s5.getName()); s3.putNextEntry(s6); FileInputStream s7=new FileInputStream(s5); int s; while ((s=s7.read())!=-1){ s3.write(s); } s7.close(); s3.closeEntry(); }else { tozip(s5,s3,name+"\\"+s5.getName()); } } } }
|