Javaでbyte[]をファイルに送る 質問する

Javaでbyte[]をファイルに送る 質問する

Java の場合:

byte[]ファイルを表す があります。

これをファイルに書き込むにはどうすればいいでしょうか (つまりC:\myfile.pdf)

InputStream で実行できることはわかっていますが、うまく実行できないようです。

ベストアンサー1

使用アパッチ コモンズ 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
}

おすすめ記事