Here you can find the source of writeFile(final File file, byte[] data)
public static boolean writeFile(final File file, byte[] data)
//package com.java2s; /*####################################################### * * Maintained by Gregor Santner, 2017- * https://gsantner.net//*w w w. j a va 2 s. c om*/ * * License: Apache 2.0 * https://github.com/gsantner/opoc/#licensing * https://www.apache.org/licenses/LICENSE-2.0 * #########################################################*/ import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStream; public class Main { public static boolean writeFile(final File file, byte[] data) { try { OutputStream output = null; try { output = new BufferedOutputStream(new FileOutputStream(file)); output.write(data); output.flush(); return true; } finally { if (output != null) { output.close(); } } } catch (Exception ex) { return false; } } public static boolean writeFile(final File file, final String content) { BufferedWriter writer = null; try { if (!file.getParentFile().isDirectory() && !file.getParentFile().mkdirs()) return false; writer = new BufferedWriter(new FileWriter(file)); writer.write(content); writer.flush(); return true; } catch (IOException e) { e.printStackTrace(); return false; } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } }