Here you can find the source of writeBytes(File file, byte[] bytes)
public static void writeBytes(File file, byte[] bytes) throws IOException
//package com.java2s; /*//from www . ja va 2 s . c om * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.RandomAccessFile; import java.io.Reader; import java.io.Writer; public class Main { public static void writeBytes(File file, byte[] bytes) throws IOException { OutputStream out = null; try { out = new FileOutputStream(file); out.write(bytes, 0, bytes.length); } finally { close(out); } } /** * Closes the streams and resources. * * @param resource * to be closed. */ public static void close(Object resource) { try { if (resource instanceof InputStream) { ((InputStream) resource).close(); } else if (resource instanceof OutputStream) { ((OutputStream) resource).close(); } else if (resource instanceof Reader) { ((Reader) resource).close(); } else if (resource instanceof Writer) { ((Writer) resource).close(); } else if (resource instanceof RandomAccessFile) { ((RandomAccessFile) resource).close(); } else if (resource != null) { throw new IllegalArgumentException("Unknown resource: " + resource); } } catch (IOException e) { } } }