Java ByteBuffer Write writeByteBuffer(ByteBuffer bbuf, String filename)

Here you can find the source of writeByteBuffer(ByteBuffer bbuf, String filename)

Description

write Byte Buffer

License

Open Source License

Declaration

public static void writeByteBuffer(ByteBuffer bbuf, String filename) 

Method Source Code

//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) {
        }

    }
}

Related

  1. writeByte(ByteBuffer dest, int off, int i)
  2. writeByteArray(byte[] array, ByteBuffer out)
  3. writeByteArray(byte[] data, ByteBuffer buffer)
  4. writeByteArray(ByteBuffer byteBuffer, byte[] bytes)
  5. writeByteArray(ByteBuffer logBuf, byte[] b)
  6. writeByteBuffer(RandomAccessFile file, ByteBuffer buffer)
  7. writeByteBuffer(WritableByteChannel channel, ByteBuffer buf, int bytesToWrite)
  8. writeBytesNoLength(ByteBuffer logBuf, byte[] b)
  9. writeByteString(ByteBuffer byteBuffer, String value)