Here you can find the source of saveBytes(byte[] b, File destFolder, String fileName, String suffix)
Parameter | Description |
---|---|
b | a parameter |
destFolder | a parameter |
fileName | a parameter |
suffix | a parameter |
public static void saveBytes(byte[] b, File destFolder, String fileName, String suffix)
//package com.java2s; /* Image to ZX Spec/*w ww. j a v a2 s. c om*/ * Copyright (C) 2014 Silent Software (Benjamin Brown) * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { /** * Saves raw byte data to the given file * * @param bytes * @param file */ public static void saveBytes(byte[] bytes, File file) { BufferedOutputStream out = null; try { if (file.exists()) file.delete(); out = new BufferedOutputStream(new FileOutputStream(file)); out.write(bytes); out.close(); } catch (IOException io) { if (out != null) { try { out.close(); } catch (Throwable t) { } } } } /** * Saves raw byte data to the given file * * @param bytes * @param file */ public static void saveBytes(byte[] bytes, File file, boolean append) { BufferedOutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file, append)); out.write(bytes); out.close(); } catch (IOException io) { if (out != null) { try { out.close(); } catch (Throwable t) { } } } } /** * Saves raw byte data to the chosen output folder, but * uses the given file filename + the given suffix * * @param b * @param destFolder * @param fileName * @param suffix */ public static void saveBytes(byte[] b, File destFolder, String fileName, String suffix) { OutputStream out = null; try { File f = new File( destFolder.getAbsolutePath() + "/" + fileName.substring(0, fileName.lastIndexOf(".")) + suffix); if (f.exists()) f.delete(); out = new FileOutputStream(f); out.write(b); out.close(); } catch (IOException io) { if (out != null) { try { out.close(); } catch (Throwable t) { } } } } }