Java ByteBuffer save to file using FileOutputStream

Description

Java ByteBuffer save to file using FileOutputStream

import java.io.FileOutputStream;
import java.nio.ByteBuffer;

public class Main {
  public static void main(String[] argv) {
    ByteBuffer b = ByteBuffer.wrap("demo2s.com".getBytes());
    /*from  w w w.  j a v  a 2 s.  c  om*/
    dumpToFile(b,"Main.java");
    System.out.println("done");
  }
    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);
        }
    }
}



PreviousNext

Related