| | |
| | | import com.anyun.exam.lib.util.ByteUtil; |
| | | import com.safeluck.aykj.utils.BytesUtils; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileOutputStream; |
| | | import java.math.BigDecimal; |
| | | import java.security.SecureRandom; |
| | | import java.text.ParseException; |
| | |
| | | import java.util.Random; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.SecretKey; |
| | |
| | | long utcTime = date.getTime()+8*60*60*1000; |
| | | return utcTime; |
| | | } |
| | | |
| | | public static void zipFolder(String srcFileString,String zipFileString) throws Exception{ |
| | | //创建zip |
| | | ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileString)); |
| | | |
| | | //创建文件 |
| | | File file = new File(srcFileString); |
| | | //压缩 |
| | | System.out.println("----->"+file.getParent()+"==="+file.getAbsolutePath()); |
| | | zipFiles(file.getParent()+File.separator,file.getName(),outZip); |
| | | outZip.finish(); |
| | | outZip.close(); |
| | | } |
| | | |
| | | /** |
| | | * 压缩文件 |
| | | * @param folderString |
| | | * @param fileString |
| | | * @param outZip |
| | | */ |
| | | private static void zipFiles(String folderString, String fileString, ZipOutputStream outZip) |
| | | throws Exception{ |
| | | System.out.println("folderString="+folderString+ "\n" + |
| | | "fileString:" + fileString + "\n=========================="); |
| | | if (outZip == null){ |
| | | return; |
| | | } |
| | | File file = new File(folderString + fileString); |
| | | if (file.isFile()){ |
| | | ZipEntry zipEntry = new ZipEntry(fileString); |
| | | FileInputStream fileInputStream = new FileInputStream(file); |
| | | outZip.putNextEntry(zipEntry); |
| | | int len = 0; |
| | | byte[] buffer = new byte[1024]; |
| | | while ((len=fileInputStream.read(buffer))!=-1){ |
| | | outZip.write(buffer,0,len); |
| | | } |
| | | outZip.closeEntry(); |
| | | }else{ |
| | | //文件夹 |
| | | String []fileList = file.list(); |
| | | //没有子文件的压缩 |
| | | if (fileList.length<=0){ |
| | | ZipEntry zipEntry = new ZipEntry(fileString+File.separator); |
| | | outZip.putNextEntry(zipEntry); |
| | | outZip.closeEntry(); |
| | | }else{ |
| | | for (int i = 0; i < fileList.length; i++) { |
| | | zipFiles(folderString+fileString+"/",fileList[i],outZip); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |