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();
    }

 

posted @ 2019-08-08 11:11  龙桑  阅读(122)  评论(0编辑  收藏  举报