开发者社区 问答 正文

用Java归档的byte []

使用Java:

我有一个byte[]代表文件的文件。

如何将此写入文件(即C:\myfile.pdf)

我知道它已经用InputStream完成了,但是我似乎无法解决。

展开
收起
保持可爱mmm 2020-01-16 15:06:32 335 分享 版权
1 条回答
写回答
取消 提交回答
  • 使用Apache Commons IO

    FileUtils.writeByteArrayToFile(new File("pathname"), myByteArray) 或者,如果您坚持要自己做...

    try (FileOutputStream fos = new FileOutputStream("pathname")) { fos.write(myByteArray); //fos.close(); There is no more need for this line since you had created the instance of "fos" inside the try. And this will automatically close the OutputStream } 问题来源于stack overflow

    2020-01-16 15:06:47
    赞同 展开评论
问答分类:
问答标签:
问答地址: