A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

public class jiami {
        public static void main(String[] args) throws IOException {
                // TODO Auto-generated method stub
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream("62667_05big.jpg"));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("胆小勿入.jpg"));
                int b;
                byte [] arr = new byte[1024];
                while((b=bis.read(arr))!=-1){
                        System.out.println(b);
                        bos.write(b);
                }
                bis.close();
                bos.close();
        }

}

评分

参与人数 1技术分 +1 收起 理由
李小然 + 1

查看全部评分

1 个回复

倒序浏览
定义的没有问题,是你的用法有问题
                 byte [] arr = new byte[1024];
                while((b=bis.read(arr))!=-1){ // 这里read(byte[])返回的是读到的长度,面不是读到的内容
                        System.out.println(b);
                        bos.write(b); // 这里应该是:bos.write(arr, 0, b);
                }

评分

参与人数 1技术分 +1 收起 理由
李小然 + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马