Java ByteBuffer Save saveBytesBufferToFile(ByteBuffer buf, String filename)

Here you can find the source of saveBytesBufferToFile(ByteBuffer buf, String filename)

Description

save Bytes Buffer To File

License

Apache License

Declaration

public static String saveBytesBufferToFile(ByteBuffer buf, String filename) throws IOException 

Method Source Code

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

Related

  1. save(Path path, ByteBuffer bb)
  2. saveAsBMP(String filename, ByteBuffer pixel_data, int width, int height)
  3. saveAsFile(File targetFile, ByteBuffer bb)
  4. saveAsTempFile(ByteBuffer byteBuffer, String extension)
  5. saveAsTGA(String filename, ByteBuffer pixel_data, int width, int height)
  6. savePageBitMask(ByteBuffer buffer, BitSet freePagesBitSet)
  7. saveStruct(ByteBuffer o, String[] struct, Object instance)