Here you can find the source of saveFileBinary(final File file, final byte[] data)
data
in a file.
Parameter | Description |
---|---|
file | File to save the data in. |
data | Data to save in the file. |
Parameter | Description |
---|---|
IOException | File exception occurred. |
public static void saveFileBinary(final File file, final byte[] data) throws IOException
//package com.java2s; /* This file is part of the project "Hilbert II" - http://www.qedeq.org * * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>. * * "Hilbert II" is free software; you can redistribute * it and/or modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */// w ww . ja va 2s . c om import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; public class Main { /** * Saves a <code>data</code> in a file. Existing files are overwritten. * * @param file File to save the data in. * @param data Data to save in the file. * @throws IOException File exception occurred. */ public static void saveFileBinary(final File file, final byte[] data) throws IOException { BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { out.write(data); } finally { out.close(); } } /** * Closes input stream without exception. * * @param in Input stream, maybe <code>null</code>. */ public static void close(final InputStream in) { if (in != null) { try { in.close(); } catch (Exception e) { // ignore } } } /** * Closes writer without exception. * * @param writer Writer, maybe <code>null</code>. */ public static void close(final Writer writer) { if (writer != null) { try { writer.close(); } catch (Exception e) { // ignore } } } /** * Closes out stream without exception. * * @param out Output stream, maybe <code>null</code>. */ public static void close(final OutputStream out) { if (out != null) { try { out.close(); } catch (Exception e) { // ignore } } } /** * Closes input reader without exception. * * @param reader Reader, maybe <code>null</code>. */ public static void close(final Reader reader) { if (reader != null) { try { reader.close(); } catch (Exception e) { // ignore } } } }