Android Text File Write writeLineTextFile(File file, String data)

Here you can find the source of writeLineTextFile(File file, String data)

Description

write Line Text File

Declaration

public static void writeLineTextFile(File file, String data) 

Method Source Code

//package com.java2s;

import java.io.File;

import java.io.PrintWriter;

public class Main {
    public static void writeLineTextFile(File file, String data) {
        PrintWriter pw = null;//from  w ww . ja  va 2 s . c om

        try {
            pw = new PrintWriter(file);

            pw.print(data);
            pw.flush();
        } catch (Exception e) {
            e.printStackTrace();
            try {
                if (pw != null) {
                    pw.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } finally {
            try {
                if (pw != null) {
                    pw.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    public static void writeLineTextFile(File file, String[] dataArray) {
        PrintWriter pw = null;

        try {
            pw = new PrintWriter(file);

            for (String data : dataArray) {
                pw.println(data);
            }

            pw.flush();
        } catch (Exception e) {
            e.printStackTrace();

            try {
                if (pw != null) {
                    pw.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } finally {
            try {
                if (pw != null) {
                    pw.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}

Related

  1. writeFileAsString(String filename, String text, String encoding)
  2. writeFileAsStringWorldWritable(File file, String text)
  3. writeFileAtomically(File file, String content, String encoding)
  4. writeFileWithBom(File file, String content, String encoding)
  5. writeLargerTextFile(File file, List aLines)
  6. writeLineTextFile(File file, String[] dataArray)
  7. writeSet2File(Set set, String filePath)
  8. writeString(String string, File file, boolean append)
  9. writeStringToFile(String content, String fileName)