• 请完成下列Java程序:读取自己的源文件并把它压缩成GZIP文件。

    注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
    import java.io.*;
    import java.util.zip.*;
    public class exl6 2 {
    public static void main{String[] arg) {
    ex16_2 obj16_2 = new ex16_2();
    obj16_2.doZip("ex16_2.java","ex16_2.gzip")
    }
    public void doZip(String strIn,String strOut
    FileInputStream in;
    FileOutputStream out;
    GZIPOutputStream gzip;
    int nFileLength;
    byte[] barray = new byte;
    try {
    in = new FileInputStream(strIn);
    out = new FileOutputStream(strOut);
    gzip = new GZIPOutputStream(out);
    while((nFileLength = in.read(barray, 0 barray.length)) > 0)
    _____________________;
    ______________________;
    gzip.close();
    } catch(Exception e) {
    e.printStackTrace();
    }
    }
    }

    正确答案:gzip.write(barray0nFileLength)     in.close()gzip.write(barray,0,nFileLength)     in.close() 解析:本题主要考查文件的读写操作。解题关键是熟悉文件读写操作,熟悉GZIP的编程模式,使用FileInputStream读取待压缩的文件,使用GZIPOutputStream进行压缩,除了压缩之外还有解压缩,但是编程的模式一样,一旦压缩数据流被打开,可以象其他数据流一样进行读写。本题中,第1个空,熟练掌握压缩数据流的写操作;第2今
  • 2021年07月14日 22时35分来自  问答库 >> 计算机类
  • 评论 0
  • 手机玩微博

    手机版 手机端
    Powered by 日新微博 © 2018 - 2020 日新网