Android Text File Write writeTextFile(File file, String str)

Here you can find the source of writeTextFile(File file, String str)

Description

write Text File

Declaration

public static void writeTextFile(File file, String str)
            throws IOException 

Method Source Code

//package com.java2s;

import java.io.*;

public class Main {
    public static void writeTextFile(File file, String str)
            throws IOException {
        DataOutputStream out = null;
        if (null != file) {
            try {
                out = new DataOutputStream(new FileOutputStream(file));
                out.write(str.getBytes());
            } finally {
                if (out != null) {
                    out.close();/*  ww w.jav  a 2  s .c o m*/
                }
            }
        }
    }

    public static void writeTextFile(File file, String[] strArray)
            throws IOException {
        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;
            try {
                out = new DataOutputStream(new FileOutputStream(file));
                out.write(str.getBytes());
            } finally {
                if (out != null) {
                    out.close();
                }
            }
        }
    }
}

Related

  1. writeToSDFile(String directory, String file_name, String text)
  2. writeFileEnd(String filepath, String text)
  3. WriteFile(String file, String message)
  4. writeNewFile(String filePath, String fileContents)
  5. writeStringToFile(File file, String data)
  6. writeTextFile(File file, String[] strArray)