Here you can find the source of saveBytes(String filename, byte[] data)
data
to the file specified by filename
.
Parameter | Description |
---|---|
filename | a parameter |
data | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void saveBytes(String filename, byte[] data) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) MOBAC developers/*from w w w .j ava2s . com*/ * * This program 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. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Saves <code>data</code> to the file specified by <code>filename</code>. * * @param filename * @param data * @throws IOException */ public static void saveBytes(String filename, byte[] data) throws IOException { FileOutputStream fo = null; try { fo = new FileOutputStream(filename); fo.write(data); } finally { closeStream(fo); } } public static void closeStream(InputStream in) { if (in == null) return; try { in.close(); } catch (IOException e) { } } public static void closeStream(OutputStream out) { if (out == null) return; try { out.close(); } catch (IOException e) { } } }