Here you can find the source of writeFile(File file, ByteBuffer bb)
public static boolean writeFile(File file, ByteBuffer bb)
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static boolean writeFile(File file, String str) { try {/* w w w. j a va 2s. c om*/ BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(str); writer.close(); return true; } catch (IOException e) { e.printStackTrace(); } return false; } public static boolean writeFile(File file, ByteBuffer bb) { try { FileChannel wChannel = new FileOutputStream(file, false).getChannel(); wChannel.write(bb); wChannel.close(); return true; } catch (IOException e) { e.printStackTrace(); } return false; } public static boolean writeFile(File file, ByteBuffer bb, long offset) { try { FileChannel wChannel = new RandomAccessFile(file, "rw").getChannel(); wChannel.write(bb, offset); wChannel.close(); return true; } catch (IOException e) { e.printStackTrace(); } return false; } }