How can I write a byte array to a file in Java?

后端 未结 8 2052
野的像风
野的像风 2020-12-08 09:07

How to write a byte array to a file in Java?

8条回答
  •  一整个雨季
    2020-12-08 09:30

    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);
    

提交回复
热议问题