/** Create a compressed file from the folder path, to the compressed file path for the Create good */public void Createzip (String from,string to) throws IOException {LIST<FILE&G T;list=getfiles (from); Zipoutputstream out=new Zipoutputstream (New FileOutputStream (new File)); for (File f:list) {InputStream in=new fileinputstream (f); String Name=getrelname (from,f); ZipEntry en=new ZipEntry (New File (from) getName () + "/" +name); En.setsize (F.length ()); Out.putnextentry (en); Out.setcomment ("Chinese test"); int len=0; Byte[]buffer=new byte[1024]; while ( -1!= (len=in.read (buffer))) {out.write (buffer, 0, Len); } in.close (); } out.close (); /** gets the relative path of the file */private string Getrelname (String From,file f) {//TODO auto-generated method stub String A=F.GETABSO Lutepath (). replace (from+ "\ \", ""); A=a.replace ("\ \", "/"); System.out.println (from+ "---" +a); return A; /** gets all the files under the path, including the */private list<file> getFiles (String sou) {list<file>list=new Arraylist<file> ;(); File F=new file (SOU); File files[]=f.listFiles (); for (file file:files) {if (File.isfile ()) {list.add (file); } else {List.addall (GetFiles (File.getpath ())); }} return list; }
##########################################
Transferred from: http://blog.csdn.net/liu149339750/article/details/7887701
##########################################
[Go] to implement file compression