Create/append byte[] to a binary file..

edited March 2016 in Share Your Work
import java.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;

void fwrite(String filename, byte[] data, boolean append){
  Path file = Paths.get(filename);
  OutputStream output = null;
    try
    {
      if(append){
        output = new BufferedOutputStream(Files.newOutputStream(file, APPEND));
      }
      else{
        output = new BufferedOutputStream(Files.newOutputStream(file, CREATE));
      }
      output.write(data);
      output.flush();
      output.close();
    }
    catch(Exception e)
    {
        System.out.println("Message: " + e);
    }
}

Comments

Sign In or Register to comment.