Java Utililty Methods Byte Array Save to File nio

List of utility methods to do Byte Array Save to File nio

Description

The list of methods to do Byte Array Save to File nio are organized into topic(s).

Method

voidfileWriteBytes(byte[] data, String file)
file Write Bytes
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);
voidwriteBytes(final byte[] bytes, final OutputStream output)
write Bytes
try (final ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
    transfer(input, output);
voidwriteHeader(File input, ByteArrayOutputStream headerStream)
write Header
try {
    BufferedReader br = new BufferedReader(new FileReader(input));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = br.readLine()) != null)
        sb.append(line).append(String.format(System.lineSeparator()));
    br.close();
    FileOutputStream outFileStream = new FileOutputStream(input);
...
voidwriteIntChars(int value, int index, byte[] buf)
Write the characters that make up this integer into the buffer Note: index is the ending location in the buffer.
if (value == Integer.MIN_VALUE) {
    System.arraycopy(INT_MIN_VALUE_BYTES, 0, buf, index - INT_MIN_VALUE_BYTES.length,
            INT_MIN_VALUE_BYTES.length);
} else {
    getIntChars(value, index, buf);
booleanwriteToBinaryFile(String filename, byte[] data)
Writes the binary data to the specified file.
return writeToBinaryFile(filename, data, false);
voidwriteToFile(File file, byte[] content)
Write function for JVM >= 1.7
Files.write(Paths.get(file.getPath()), content, StandardOpenOption.SYNC, StandardOpenOption.WRITE,
        StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);