如何在Java中将字节数组写入文件? [英] How can I write a byte array to a file in Java?
本文介绍了如何在Java中将字节数组写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用Java编写字节数组到文件?
How to write a byte array to a file in Java?
推荐答案
你可以使用 IOUtils.write(byte [来自 Apache Commons IO 的数据,OutputStream输出。
You can use IOUtils.write(byte[] data, OutputStream output) from Apache Commons IO.
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128);
SecretKey key = kgen.generateKey();
byte[] encoded = key.getEncoded();
FileOutputStream output = new FileOutputStream(new File("target-file"));
IOUtils.write(encoded, output);
这篇关于如何在Java中将字节数组写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文