Here you can find the source of saveBytesBufferToFile(ByteBuffer buf, String filename)
public static String saveBytesBufferToFile(ByteBuffer buf, String filename) throws IOException
//package com.java2s; //License from project: Apache 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 String saveBytesBufferToFile(ByteBuffer buf, String filename) throws IOException { return saveBytesBufferToFile(buf, new File(filename)); }/*w w w . j a v a 2 s .c o m*/ public static String saveBytesBufferToFile(ByteBuffer buf, File file) throws IOException { boolean append = false; @SuppressWarnings("resource") FileChannel outChannel = new FileOutputStream(file, append).getChannel(); buf.rewind(); outChannel.write(buf); outChannel.close(); return file.getAbsolutePath(); } }