Java Byte Array Save to File nio writeToFile(File file, byte[] content)

Here you can find the source of writeToFile(File file, byte[] content)

Description

Write function for JVM >= 1.7

License

Apache License

Parameter

Parameter Description
file a parameter
content a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static void writeToFile(File file, byte[] content) throws Exception 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.nio.file.Files;

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

public class Main {
    /**/*from  ww w  . j av a 2 s .c  om*/
     * Write function for JVM >= 1.7
     * @param file
     * @param content
     * @throws Exception
     */
    public static void writeToFile(File file, byte[] content) throws Exception {
        Files.write(Paths.get(file.getPath()), content, StandardOpenOption.SYNC, StandardOpenOption.WRITE,
                StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
    }
}

Related

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