Here you can find the source of writeFile(byte data[], File file)
Parameter | Description |
---|---|
data | The byte array to write to the file |
file | The file to which the byte array is written |
Parameter | Description |
---|---|
IOException | if an error occurred. |
public static boolean writeFile(byte data[], File file) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**/*from www .j a v a 2 s . c om*/ *** Writes a byte array to the specified file *** * @param data * The byte array to write to the file *** @param file * The file to which the byte array is written *** @return True if the bytes were successfully written to the file *** @throws IOException * if an error occurred. **/ public static boolean writeFile(byte data[], File file) throws IOException { return writeFile(data, file, false); } /** *** Writes a byte array to the specified file *** * @param data * The byte array to write to the file *** @param file * The file to which the byte array is written *** @param append * True to append the bytes to the file, false to overwrite. *** @return True if the bytes were successfully written to the file *** @throws IOException * if an error occurred. **/ public static boolean writeFile(byte data[], File file, boolean append) throws IOException { if ((data != null) && (file != null)) { FileOutputStream fos = null; try { fos = new FileOutputStream(file, append); fos.write(data, 0, data.length); return true; } finally { try { fos.close(); } catch (Throwable t) {/* ignore */ } } } return false; } }