唐祖庭 2021-10-23 15:57 采纳率: 95.9%
浏览 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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?