Java File Write via ByteBuffer writeFileAsByteArray(File file, byte[] par2Data)

Here you can find the source of writeFileAsByteArray(File file, byte[] par2Data)

Description

write File As Byte Array

License

Open Source License

Declaration

public static void writeFileAsByteArray(File file, byte[] par2Data) throws IOException 

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 writeFileAsByteArray(File file, byte[] par2Data) throws IOException {
        ByteBuffer bb;// w  ww  . ja v  a2 s.  co m
        FileChannel fc = null;
        try {
            fc = new FileOutputStream(file).getChannel();
            bb = ByteBuffer.wrap(par2Data);
            fc.write(bb);
        } finally {
            if (fc != null)
                fc.close();
        }
    }
}

Related

  1. writeEmpty()
  2. writeFC(String fname, float[] res)
  3. writeFile(File file, byte[] bytes)
  4. writeFile(File file, byte[] data)
  5. writeFile(String source, File outputFile)
  6. writeFileAsStringArray(File file, String[] par2DataArray)
  7. writeFileNIO(String txt, File fyl)
  8. writeFloat(OutputStream os, float val, ByteOrder bo)
  9. writeInt(OutputStream os, int val, ByteOrder bo)