Java Byte Array Save to File nio fileWriteBytes(byte[] data, String file)

Here you can find the source of fileWriteBytes(byte[] data, String file)

Description

file Write Bytes

License

Open Source License

Declaration

public static void fileWriteBytes(byte[] data, String file) throws IOException 

Method Source Code


//package com.java2s;

import java.io.File;
import java.io.IOException;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class Main {
    public static void fileWriteBytes(byte[] data, String file) throws IOException {
        File f = new File(file);
        if (f.exists())
            if (!f.delete())
                throw new IOException("Unable to delete file.");

        Files.write(Paths.get(file), data, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    }/*from   w  ww .  j  a v a2  s  . c om*/
}

Related

  1. writeBytes(final byte[] bytes, final OutputStream output)
  2. writeHeader(File input, ByteArrayOutputStream headerStream)
  3. writeIntChars(int value, int index, byte[] buf)
  4. writeToBinaryFile(String filename, byte[] data)