Here you can find the source of writeByteBuffer(ByteBuffer bbuf, String filename)
public static void writeByteBuffer(ByteBuffer bbuf, String filename)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.io.*; public class Main { public static void writeByteBuffer(ByteBuffer bbuf, String filename) { // Write bbuf to filename File file;//from w ww. j a v a 2s . c om try { //Get log file String logfile = "C:\\" + filename + ".txt"; file = new File(logfile); boolean exists = file.exists(); if (!exists) { //create a new, empty node file try { file = new File(logfile); boolean success = file.createNewFile(); } catch (IOException e) { System.out.println("Create Event Log file failed!"); } } try { // Create a writable file channel FileChannel wChannel = new FileOutputStream(file, true).getChannel(); // Write the ByteBuffer contents; the bytes between the ByteBuffer's // position and the limit is written to the file wChannel.write(bbuf); // Close the file wChannel.close(); } catch (IOException e) { } } catch (java.lang.Exception e) { } } }