Java Utililty Methods Write Byte Array to File

List of utility methods to do Write Byte Array to File

Description

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

Method

voidwriteFile(byte[] data, File outFile)
Writes byte array to file.
FileOutputStream fos = null;
try {
    if (outFile.getParentFile() != null) {
        outFile.getParentFile().mkdirs();
    fos = new FileOutputStream(outFile);
    fos.write(data);
} finally {
...
voidwriteFile(byte[] data, String fileName)
write File
OutputStream out = new FileOutputStream(fileName);
out.write(data);
out.close();
voidwriteFile(byte[] data, String filePath)
write File
FileOutputStream fos = new FileOutputStream(new File(filePath));
fos.write(data);
fos.close();
StringwriteFile(byte[] data, String path, boolean overwrite)
Writes a file to the given path, appending digits to the end of the file name until it is unique.
OutputStream os = null;
try {
    if (data == null)
        throw new IOException("Data is null");
    String path2 = path;
    File f = new File(path2);
    int index = 0;
    while (f.exists() && !overwrite) {
...
voidwriteFile(byte[] fileData, String path)
Writes the given byte array to a file.
File fileToWrite = new File(path);
if (!fileToWrite.exists()) {
    File pathToFile = new File(fileToWrite.getParent());
    pathToFile.mkdirs();
    fileToWrite.createNewFile();
FileOutputStream outStream = null;
try {
...
voidwriteFile(byte[] outputBytes, String outputFile)
write File
OutputStream os = new FileOutputStream(outputFile);
os.write(outputBytes);
os.flush();
os.close();
voidwriteFile(File f, byte[] data)
write File
try {
    RandomAccessFile raf = new RandomAccessFile(f, "rw");
    try {
        raf.write(data);
    } finally {
        raf.close();
} catch (IOException e) {
...
voidwriteFile(File file, byte[] b)
write File
FileOutputStream fos = new FileOutputStream(file);
fos.write(b);
fos.close();
voidwriteFile(File file, byte[] content)
write File
FileOutputStream outputStream = new FileOutputStream(file, false);
try {
    for (int i = 0; i < content.length; i++) {
        outputStream.write(content[i]);
} finally {
    outputStream.close();
voidwriteFile(File file, byte[] context, boolean append)
write File
FileOutputStream fos = null;
if (!file.getParentFile().exists()) {
    file.getParentFile().mkdirs();
} else if (append) {
    fos = new FileOutputStream(file, append);
if (fos == null) {
    fos = new FileOutputStream(file);
...