Android Utililty Methods Text File Write

List of utility methods to do Text File Write

Description

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

Method

voidwriteFile(File file, String content)
writes a file with the given content.
Writer w = new FileWriter(file);
if (content != null)
    w.write(content);
w.flush();
w.close();
voidwriteFile(File file, String content, String encoding)
write File
if (!file.exists()) {
    file.getParentFile().mkdirs();
FileOutputStream out = null;
try {
    out = new FileOutputStream(file);
    out.write(content.getBytes(encoding));
} finally {
...
voidwriteFile(File file, String text)
write File
FileWriter out = null;
try {
    out = new FileWriter(file);
    out.write(text);
} finally {
    if (out != null) {
        out.close();
booleanwriteFile(File out, String text)
write File
try {
    return writeFile(new FileOutputStream(out), text);
} catch (Exception e) {
    e.printStackTrace();
    return false;
booleanwriteFile(OutputStream output, String text)
write File
OutputStreamWriter out = null;
BufferedWriter buffer = null;
try {
    out = new OutputStreamWriter(output);
    buffer = new BufferedWriter(out);
    buffer.write(text);
} catch (Exception e) {
    e.printStackTrace();
...
voidwriteFile(String file, T data, boolean append)
write File
FileWriter writer = null;
try {
    writer = new FileWriter(file, append);
    writer.write(data.toString());
    writer.flush();
} catch (IOException e) {
    e.printStackTrace();
} finally {
...
voidwriteFile(String fileName, String content)
write File
writeFile(fileName, content.getBytes());
voidwriteFile(String fileName, String text)
write File
FileWriter fw = new FileWriter(fileName, true);
try {
    fw.write(text, 0, text.length());
} catch (IOException ioe) {
    throw new IOException("Write text to " + fileName + " fail!");
} finally {
    fw.close();
voidwriteFile(String fileName, String text, boolean isAppend)
write File
FileWriter fw = new FileWriter(fileName, isAppend);
try {
    fw.write(text, 0, text.length());
} catch (IOException ioe) {
    throw new IOException("Write text to " + fileName + " fail!");
} finally {
    fw.close();
voidwriteFile(String filePath, String content)
write File
FileOutputStream outSTr = new FileOutputStream(new File(filePath));
BufferedOutputStream Buff = new BufferedOutputStream(outSTr);
Buff.write(content.getBytes());
Buff.flush();
Buff.close();