Android Utililty Methods Byte Array Save to File

List of utility methods to do Byte Array Save to File

Description

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

Method

voidcopy(byte[] input, OutputStream output)
Copy bytes from a byte[] to an OutputStream.
output.write(input);
voidcopy(byte[] input, Writer output)
Copy and convert bytes from a byte[] to chars on a Writer.
ByteArrayInputStream in = new ByteArrayInputStream(input);
copy(in, output);
voidcopy(byte[] input, Writer output, String encoding)
Copy and convert bytes from a byte[] to chars on a Writer, using the specified encoding.
ByteArrayInputStream in = new ByteArrayInputStream(input);
copy(in, output, encoding);
voidsaveBytes(@NotNull File file, @NotNull byte[] bytes)
Saves the contents of a byte[] to the specified File .
FileOutputStream stream = null;
try {
    stream = new FileOutputStream(file);
    stream.write(bytes);
} finally {
    if (stream != null) {
        stream.close();
voidsaveFile(byte[] data, String fileName)
save File
if (!DESTINY_DIR.exists() && !DESTINY_DIR.mkdirs()) {
    return;
File mainPicture = new File(DESTINY_DIR, fileName);
try {
    FileOutputStream fos = new FileOutputStream(mainPicture);
    fos.write(data);
    fos.close();
...
voidwriteBytes(File file, boolean append, byte[] bytes)
write bytes into file
if (bytes.length == 0)
    return;
FileOutputStream output = new FileOutputStream(file, append);
output.write(bytes);
output.flush();
output.close();
voidwriteBytes(byte[] bytes, File file, boolean append)
Writes bytes into file.
Check.arg().notNull(bytes);
Check.arg().notNull(file);
if (file.isDirectory())
    throw new IllegalArgumentException("file = " + file.getPath()
            + " refers to directory, not a normal text file");
OutputStream out = null;
try {
    out = new FileOutputStream(file, append);
...
voidwriteFile(String fileName, byte[] content)
write File
try {
    FileOutputStream fos = new FileOutputStream(fileName);
    fos.write(content);
    fos.flush();
    fos.close();
} catch (Exception e) {
FilewriteFile(String fileName, byte[] datas, boolean overwrite)
write File
File file = new File(fileName);
if (file.exists()) {
    if (!overwrite) {
        fileName = Math.random() + fileName;
        file = new File(fileName);
    } else {
        file.delete();
file.createNewFile();
FileOutputStream fos = new FileOutputStream(fileName);
fos.write(datas);
fos.close();
return file;
FilewriteFile(String path, String fileName, byte[] datas, boolean overwrite)
Write a file to disk
File file = new File(path);
if (!file.exists() || !file.isDirectory()) {
    file.mkdirs();
if (!path.endsWith(File.separator)) {
    path += File.separator;
file = new File(path + fileName);
...