这是一个数据压缩的Java代码,这个程序什么都没出来,为什么呢?

时间:2018-11-27 22:31:02

标签: java compression

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package FileComp;

import java.io.*;
import java.util.zip.*;


public class Compress {


    public static void compress(File source, File destination) throws IOException
    {
        byte[] buffer = new byte[1024];
        FileInputStream fs = new FileInputStream(source);
        FileOutputStream fo = new FileOutputStream(destination);
        GZIPOutputStream gz = new GZIPOutputStream(fo);
        int read;

        while((read = fs.read(buffer)) != -1)
        {
            gz.write(buffer, 0, read);
        }
        gz.finish();
        gz.close();
        fo.close();
        fs.close();

    }

    public static void main(String[] args)
    {
        File source = new File("C:\\Users\\MASTER\\Desktop\\z.txt");
        File destination = new File("C:\\Users\\MASTER\\Desktop\\oCompress.txt");
        try
        {
            compress(source, destination);
        }
        catch(IOException e)
        {
            System.out.println(e);
        }
    }

}

0 个答案:

没有答案