zoukankan      html  css  js  c++  java
  • JAVA-文件压缩

    package com.MakeZIP;
    
    import java.io.File;
    
    import org.apache.tools.ant.Project;
    import org.apache.tools.ant.taskdefs.Zip;
    import org.apache.tools.ant.types.FileSet;
    
    public class MyZIP {
        private static File file;
        private MyZIP(String outPath){
            boolean f = isName(outPath);
            if(f){
                file = new File(outPath);
                if(file.exists()){
                    System.err.println("压缩文件已存在");
                }
            }else{
                System.err.println("压缩文件格式错误");
            }
        }
        
        public static void corress(String inPath){
            File file2 = new File(inPath);
            if(file2.exists() && file2.isDirectory()){
                System.out.println("压缩中。。。。。。");
                Zip zip = new Zip();
                Project pro = new Project();
                zip.setProject(pro);
                zip.setDestFile(file);
                FileSet fileSet = new FileSet();
                fileSet.setProject(pro);
                fileSet.setDir(file2);
                zip.add(fileSet);
                zip.execute();
                System.out.println("压缩完成");
            }else{
                System.err.println("要压缩的文件夹不存在");
            }
        }
        
        public static void main(String args[]){
            MyZIP my = new MyZIP("E:/a.zip");
            my.corress("E:/test");
        }
        
        public static boolean isName(String path){
            String name = path;
            name = name.substring(name.lastIndexOf("."), name.length());
            if(name.equals(".zip") || name.equals(".tar") || name.equals(".tgz")){
                return true;
            }
            return false;
        }
    }
  • 相关阅读:
    git分支管理策略
    git解决冲突
    git分支创建和合并
    git连接远程库
    git删除文件
    git撤销修改
    4k测试网站
    Windows10通过TightVNC远程连接Ubuntu18.04
    robot报告合并输出
    python 传参中的*和**
  • 原文地址:https://www.cnblogs.com/zqzdong/p/4840353.html
Copyright © 2011-2022 走看看