Dump the given ByteBuffer 's bytes to a file. - Java java.nio

Java examples for java.nio:ByteBuffer File

Description

Dump the given ByteBuffer 's bytes to a file.

Demo Code


//package com.java2s;
import java.io.*;
import java.nio.ByteBuffer;

public class Main {
    /**// w w  w  .j a v a2 s.c o m
     * Dump the given {@link ByteBuffer}'s bytes to a file.
     *
     * @param buf The {@link ByteBuffer} to dump.
     * @param fileName The name of the file to dump to.
     */
    public static void dumpToFile(ByteBuffer buf, String fileName) {
        try {
            final FileOutputStream fos = new FileOutputStream(fileName);
            fos.write(buf.array());
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

Related Tutorials