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(String filepath, String text)
write File
OutputStreamWriter wr = null;
try {
    File file = new File(filepath);
    if (!file.exists()) {
        file.getParentFile().mkdirs();
    wr = new OutputStreamWriter(new FileOutputStream(filepath,
            false), "UTF8");
...
booleanwriteStringToFile(String text, String filePath)
write String To File
OutputStream os = null;
try {
    File file = new File(filePath);
    if (file.exists()) {
        file.delete();
    file.createNewFile();
    os = new FileOutputStream(file);
...
BooleanwriteToSDFile(String directory, String file_name, String text)
write To SD File
File root = Environment.getExternalStorageDirectory();
File dir = new File(root.getAbsolutePath() + "/" + directory);
dir.mkdirs();
File file = new File(dir, file_name);
try {
    FileOutputStream f = new FileOutputStream(file);
    PrintWriter pw = new PrintWriter(f);
    pw.println(text);
...
voidwriteFileEnd(String filepath, String text)
write File End
OutputStreamWriter wr = null;
try {
    File file = new File(filepath);
    if (!file.exists()) {
        file.getParentFile().mkdirs();
    wr = new OutputStreamWriter(
            new FileOutputStream(filepath, true), "UTF8");
...
voidWriteFile(String file, String message)
Write File
File f = new File(file);
if (!f.exists()) {
    f.createNewFile();
FileOutputStream fout = new FileOutputStream(file);
byte[] bytes = message.getBytes();
fout.write(bytes);
fout.close();
...
voidwriteNewFile(String filePath, String fileContents)
write New File
File f = new File(filePath);
if (f.exists()) {
    f.delete();
try {
    FileWriter fstream = new FileWriter(f);
    BufferedWriter out = new BufferedWriter(fstream);
    out.write(fileContents);
...
voidwriteStringToFile(File file, String data)
write String To File
FileWriter writer = null;
try {
    if (file.exists())
        file.delete();
    file.createNewFile();
    writer = new FileWriter(file);
    writer.write(data);
    writer.close();
...
voidwriteTextFile(File file, String str)
write Text File
DataOutputStream out = null;
if (null != file) {
    try {
        out = new DataOutputStream(new FileOutputStream(file));
        out.write(str.getBytes());
    } finally {
        if (out != null) {
            out.close();
...
voidwriteTextFile(File file, String[] strArray)
write Text File
String str = "";
if (null != file && null != strArray) {
    for (int i = 0; i < strArray.length; i++) {
        str += strArray[i];
        if (i != strArray.length - 1)
            str += "\r\n";
    DataOutputStream out = null;
...