⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testbytearrayoutputstream.java

📁 本书是一本为Java学习者在基础内容学习结束后进行课程设计时提供参考的指导书
💻 JAVA
字号:
package apibook.c3.s7;import java.io.*;import java.util.zip.*;//public class TestByteArrayOutputStream {  public TestByteArrayOutputStream() {  }  public static void main(String[] args) {    try {        FileInputStream in = new FileInputStream(args[0]);        // Create compressed stream that writes to byte array output stream        ByteArrayOutputStream b = new ByteArrayOutputStream();        GZIPOutputStream out = new GZIPOutputStream(b);        byte[] buf = new byte[512];        int howmany;        while ((howmany = in.read(buf)) > 0) {            out.write(buf, 0, howmany);        }        in.close();        out.flush();        byte[] compressedBytes = b.toByteArray(); // get byte array        b.writeTo(new FileOutputStream(args[1])); // write to file        out.close();                              // closes both out and b        System.out.println("compressed size: " + compressedBytes.length);        // ... do something with byte array    } catch (IOException e) {        System.out.println(e);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -