分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

commons-compress(apache压缩工具包)

发布时间:2023-09-06 02:27责任编辑:苏小强关键词: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会进行详细讲解

commons-compress(apache压缩工具包)

原文地址:https://www.cnblogs.com/erdanyang/p/10158688.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved