集册 Java实例教程 压缩到文件

压缩到文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

374
压缩到文件

/*来自 
 时 代 J a v a 公 众 号*/

//package com.nowjava;

import java.io.*;

import java.util.zip.GZIPOutputStream;


public class Main {

    public static void compressToFile(File dest, String str)

            throws IOException {

        if (str == null) {

            return;

        }


        GZIPOutputStream zipOut = null;


        try {//nowjava.com - 时代Java 提供

            zipOut = new GZIPOutputStream(new FileOutputStream(dest));

            zipOut.write(str.getBytes());

        } finally {

            if (zipOut != null) {

                try {

               
展开阅读全文