Android Text File Write writeLineTextFile(File file, String[] dataArray)

Here you can find the source of writeLineTextFile(File file, String[] dataArray)

Description

write Line Text File

Declaration

public static void writeLineTextFile(File file, String[] dataArray) 

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.jav a2s.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. writeFileAsStringWorldWritable(File file, String text)
  2. writeFileAtomically(File file, String content, String encoding)
  3. writeFileWithBom(File file, String content, String encoding)
  4. writeLargerTextFile(File file, List aLines)
  5. writeLineTextFile(File file, String data)
  6. writeSet2File(Set set, String filePath)
  7. writeString(String string, File file, boolean append)
  8. writeStringToFile(String content, String fileName)
  9. writeStringToFile(String content, String fileName, boolean append)