Here you can find the source of writeToFile(String name, ByteBuffer bb)
public static void writeToFile(String name, ByteBuffer bb)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static void writeToFile(String name, ByteBuffer bb) { try {//from ww w .j a v a2 s .c o m File file = new File(name); boolean append = false; FileOutputStream fos = new FileOutputStream(file, append); FileChannel wChannel = fos.getChannel(); bb.rewind(); wChannel.write(bb); wChannel.force(true); fos.close(); } catch (IOException e) { e.printStackTrace(); } } }