Here you can find the source of writeFile(byte[] data, String outfile)
public static void writeFile(byte[] data, String outfile) throws IOException
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.Channels; import java.nio.channels.FileChannel; public class Main { public static void writeFile(byte[] data, String outfile) throws IOException { FileOutputStream fout = null; FileChannel fc = null;/* ww w . j a va2 s.c om*/ try { fout = new FileOutputStream(outfile); fc = fout.getChannel(); fc.transferFrom(Channels.newChannel(new ByteArrayInputStream(data)), 0, data.length); } catch (Exception e) { e.printStackTrace(); } finally { if (fc != null) fc.close(); if (fout != null) fout.close(); } } public static void writeFile(String body, String outfile) throws Exception { byte[] bits = null; try { bits = body.getBytes("utf-8"); } catch (Exception e) { bits = body.getBytes(); } writeFile(bits, outfile); } }