| | |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.zip.ZipEntry; |
| | |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 指定文件夹目录删除文件夹*/ |
| | | public static void delDir(String path) { |
| | | try { |
| | | Path dirPath = Paths.get(path); |
| | | if (Files.exists(dirPath) && Files.isDirectory(dirPath)) { |
| | | File dirPathFile = dirPath.toFile(); |
| | | if (null == dirPathFile) { |
| | | return; |
| | | } |
| | | File[] files = dirPathFile.listFiles(); |
| | | if (null == files) { |
| | | return; |
| | | } |
| | | for (File file : files) { |
| | | if(file.isDirectory()){ //先判断是不是文件夹 |
| | | delDir(file.getPath()); |
| | | } |
| | | else{ //这样就覆盖到了删除失效的软链接情况 |
| | | file.delete(); |
| | | } |
| | | } |
| | | Files.delete(dirPath); |
| | | } |
| | | } catch (Exception e) { |
| | | System.out.println("删除目录失败,path = {}"+path); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | /** 测试压缩方法1 */ |
| | | FileOutputStream fos1 = new FileOutputStream(new File("D:\\IDEAWorkSpace\\CadDrawManager\\target\\face.zip")); |
| | | ZipUtils.toZip("D:\\IDEAWorkSpace\\CadDrawManager\\target\\face", fos1,true); |
| | | //FileOutputStream fos1 = new FileOutputStream(new File("D:\\IDEAWorkSpace\\CadDrawManager\\target\\face.zip")); |
| | | //ZipUtils.toZip("D:\\IDEAWorkSpace\\CadDrawManager\\target\\face", fos1,true); |
| | | |
| | | /** 测试压缩方法2 */ |
| | | /*List<File> fileList = new ArrayList<>(); |
| | |
| | | fileList.add(new File("D:/Java/jdk1.7.0_45_64bit/bin/java.exe")); |
| | | FileOutputStream fos2 = new FileOutputStream(new File("c:/mytest02.zip")); |
| | | ZipUtils.toZip(fileList, fos2);*/ |
| | | delDir("D:\\IDEAWorkSpace\\CadDrawManager\\target\\downLoad"); |
| | | } |
| | | } |