正在努力学习的小白袁 2023-03-31 12:36 采纳率: 87%
浏览 11
已结题

为什么我的fileoutputstream的write方法不能直接传入byte的数组?

为什么我的fileoutputstream的write方法不能直接传入byte的数组?


 public void m() {
        String path="D:\\hello.txt";
        FileOutputStream fileOutputStream=null;
        try {
             fileOutputStream=new FileOutputStream(path);
             //写入内容方式一:
            //fileOutputStream.write('H');
            //写入内容方式二:
            String str="helloWorld";
            Byte[] bytes = new Byte[str.length()];
            for(int i=0;i<str.length();i++){
                bytes[i]=(byte)(str.charAt(i));
            }
            for(int i=0;i<bytes.length;i++){
                System.out.print(bytes[i]+" ");
            }
            fileOutputStream.write(bytes);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

第十八行说我编译出错了

img

  • 写回答

2条回答 默认 最新

  • Huazie 全栈领域优质创作者 2023-03-31 13:22
    关注

    它的入参是基本类型 byte 数组,不是 包装类 Byte数组

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日
  • 修改了问题 3月31日
  • 创建了问题 3月31日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改