34.2 字节流 InputStreamReader OutputStreamWriter

使用方法同字符流,不一样的是数据类型是字节

copydemo

 public static void main(String[] args) throws IOException {
        InputStream ips = new FileInputStream("D:\java\a.jpg");
        OutputStream ops = new FileOutputStream("test.jpg");

        byte[] by = new byte[5];
        int len;
        while ((len=ips.read(by))!=-1) {
            ops.write(by,0,len);
            ops.flush();
        }

        ops.close();
        ips.close();
    }
原文地址:https://www.cnblogs.com/longesang/p/11320009.html