唐祖庭 2021-10-23 15:57 采纳率: 93.3%
浏览 29
已结题

java 出错的地方 while((readCount = bi.read(bytes))!= -1) bo.write(bytes, 0, readCount); 爆红了

java: 找不到符号
符号: 方法 read(byte[])
位置: 类型为java.io.BufferedOutputStream的变量 bi

 public static void main(String[] args) {
        //创建缓冲输出流对象
        BufferedOutputStream bi =new BufferedOutputStream(new FileOutputStream("D:\\"));
        //创建缓冲输入流对象
        BufferedInputStream bo =new BufferedInputStream(new FileInputStream(""));
        long start = System.currentTimeMillis();
        //边读边写
        //单字节
        //copy1(bi,bo);
        //多字节的方式
        int readCount;
        byte[] bytes = new byte[1024];
        while((readCount = bi.read(bytes))!= -1) bo.write(bytes, 0, readCount);
        long end = System.currentTimeMillis();
        System.out.println("耗时:"+(end - start)+ "ms");
        // close
        bi.close();
        bo.close();
    }

    private static void copy1(BufferedInputStream bi, BufferedOutputStream bo) throws IOException{
        int readData;
        while ((readData =bi.read()) != -1){
            bo.write(readData);
        }
    }
}

img

  • 写回答

1条回答 默认 最新

  • huang_ftpjh 2021-10-23 16:46
    关注

    BufferedOutputStream 只有write方法

    img


    你自己命名时搞混了

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月31日
  • 已采纳回答 10月23日
  • 创建了问题 10月23日

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵