Java ByteBuffer Write writeToFile(String name, ByteBuffer bb)

Here you can find the source of writeToFile(String name, ByteBuffer bb)

Description

write To File

License

Open Source License

Declaration

public static void writeToFile(String name, ByteBuffer bb) 

Method Source Code


//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();
        }
    }
}

Related

  1. writeStringToBuffer(ByteBuffer buffer, String message)
  2. writeTo(ByteBuffer buffer, File file)
  3. writeToChannel(final WritableByteChannel destChannel, final ByteBuffer buffer)
  4. writeToChannel(WritableByteChannel chan, ByteBuffer buffer)
  5. writeToChannel(WritableByteChannel dst, ByteBuffer src)
  6. writeTs(ByteBuffer is, long ts)
  7. writetUnsignedInt(ByteBuffer buffer, long value)
  8. writeUB2(ByteBuffer buffer, int i)
  9. writeUnsigned(int num, int size, ByteBuffer out)