Java tutorial
//package com.java2s; import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void writeBytes(byte[] data, String path) throws IOException { writeBytes(touch(path), data); } public static void writeBytes(File dest, byte[] data) throws IOException { writeBytes(dest, data, 0, data.length, false); } public static void writeBytes(File dest, byte[] data, int off, int len, boolean append) throws IOException { if (dest.exists() == true) { if (dest.isFile() == false) { throw new IOException("Not a file: " + dest); } } FileOutputStream out = null; try { out = new FileOutputStream(dest, append); out.write(data, off, len); } finally { close(out); } } public static File touch(String fullFilePath) throws IOException { if (fullFilePath == null) { return null; } File file = new File(fullFilePath); file.getParentFile().mkdirs(); if (!file.exists()) file.createNewFile(); return file; } public static void close(Closeable closeable) { if (closeable == null) return; try { closeable.close(); } catch (IOException e) { } } }