zoukankan      html  css  js  c++  java
  • commons-compress(apache压缩工具包)

    一、添加压缩文件:

    package aaaaa.my.test.cmdoption;
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.io.PrintWriter;
    import java.nio.file.Paths;
    import org.apache.commons.compress.archivers.ArchiveOutputStream;
    import org.apache.commons.compress.archivers.ArchiveStreamFactory;
    import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class Main {
        private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String input = "D:\eclipseWorkspace\cmdoption\src";
            String output = "D:\eclipseWorkspace\cmdoption\target";
            input = new File(input).getPath();//路径标准化
            output = new File(output).getPath();//路径标准化
            LOGGER.info(input);
            LOGGER.info(output);
            OutputStream outputStream = null;
            try {
                outputStream = new FileOutputStream(Paths.get(output, "erdan.csar").toFile());
                ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", outputStream);
                zos.putArchiveEntry(new ZipArchiveEntry("TOSCA-Metadata/TOSCA.meta"));
                PrintWriter pw = new PrintWriter(zos);
                pw.println("TOSCA-Meta-Version: 1.0");
                pw.println("CSAR-Version: 1.0");
                String versionString = "Created-By: Winery " + "zte";
                pw.println(versionString);
                pw.println("Entry-Definitions: " + "Definitions/" + "serviceTemplateId" + "."
                    + "yaml");
                pw.println();
                pw.println(
                    "Name: " + "Definitions/" + "serviceTemplateId" + "." + "yaml");
                pw.println("Content-Type: " + "application/vnd.oasis.tosca.definitions");
                pw.println();
                pw.flush();
                pw.close();
                zos.closeArchiveEntry();
                zos.flush();
                zos.close();
            }catch(Exception e) {
                
            }finally {
                if(outputStream != null) {
                    try {
                        outputStream.close();
                    }catch(Exception e) {
                        
                    }    
                }
            }    
        }
    }

    后面研究完java.io会进行详细讲解

  • 相关阅读:
    统计任意字符串中字符出现次数,利用HashMap实现
    常用控件的使用方法
    Opencv读取图片和视频
    复制文件夹(多级递归)
    将指定文件中的数据存入集合中
    将集合中的学生对象输出到指定文件中
    利用缓冲字符输入流读取学生姓名名单实现点名
    字符流中的编码和解码分析
    字节缓冲流和基本字节流读取文件(一个字节读取,一个字节数组读取)
    路径中““、“/“的区别
  • 原文地址:https://www.cnblogs.com/erdanyang/p/10158688.html
Copyright © 2011-2022 走看看