Here you can find the source of writeFileAsBytes(String fullPath, byte[] bytes)
public static void writeFileAsBytes(String fullPath, byte[] bytes) throws IOException
//package com.java2s; /**/*from ww w .j av a 2 s . c o m*/ * Copyright 2010, Alvin Alexander, http://devdaily.com. * This software is distributed under the terms of the * GNU General Public License. * * This file is part of an application named JustWrite. * * JustWrite 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 3 of the License, or * (at your option) any later version. * * JustWrite 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 JustWrite. If not, see <http://www.gnu.org/licenses/>. * */ import java.io.*; public class Main { /** * Write an array of bytes to a file. Presumably this is binary data; for plain text * use the writeFile method. */ public static void writeFileAsBytes(String fullPath, byte[] bytes) throws IOException { OutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(fullPath)); InputStream inputStream = new ByteArrayInputStream(bytes); int token = -1; while ((token = inputStream.read()) != -1) { bufferedOutputStream.write(token); } bufferedOutputStream.flush(); bufferedOutputStream.close(); inputStream.close(); } }