• Java实现添加压缩文件


    package junittest;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    
    public class Download {
    
    	public static void main(String[] args) throws Exception{
    		//将文件以二进制的形式读取到数组中
    		File inputFile=new File("C:/Users/Rye/Downloads/ing/5PBfYSkT.torrent");
    		FileInputStream fileInputStream=new FileInputStream(inputFile);
    		byte[] inOutByte=new byte[fileInputStream.available()];
    		fileInputStream.read(inOutByte);
    		//指定输出文件及输出过程
    		File fileOut=new File("D:/Out.zip");//指定输出位置
    		FileOutputStream fileOutputStream=new FileOutputStream(fileOut);//以流的形式输出
    		ZipOutputStream zipOut=new ZipOutputStream(fileOutputStream);//注入到Zip中,以Zip的形式输出
    		//在压缩文件中创建文件实体
    		ZipEntry entry=new ZipEntry(inputFile.getName());
    		zipOut.putNextEntry(entry);
    		//将数组中的数据注入到ZipOutputStream中
    		zipOut.write(inOutByte);
    		//关闭流
    		fileInputStream.close();
    		zipOut.closeEntry();
    		zipOut.close();
    		fileOutputStream.close();
    	}
    }

    Reference:

    [1] Richard-Lui, java上传文件跟批量下载文件, http://blog.csdn.net/zhifeiyu2008/article/details/15758653

  • 相关阅读:
    浅谈flume
    浅谈storm
    浅谈zookeeper
    IntelliJ IDEA 使用教程
    浅谈spark
    添加本地jar包到maven仓库
    eclipse通过maven进行打编译
    pom.xml中添加远程仓库
    maven编译错误maven-assembly-plugin:2.2-beta-5:assembly (default-cli) on project
    最长上升子序列
  • 原文地址:https://www.cnblogs.com/ryelqy/p/10104167.html
Copyright © 2020-2023  润新知