Android Text File Write writeFile(File out, String text)

Here you can find the source of writeFile(File out, String text)

Description

write File

Declaration

public static boolean writeFile(File out, String text) 

Method Source Code

//package com.java2s;

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStream;
import java.io.OutputStreamWriter;

public class Main {
    public static boolean writeFile(File out, String text) {
        try {//from ww w . j  av a2 s.c  o m
            return writeFile(new FileOutputStream(out), text);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean writeFile(OutputStream output, String text) {
        OutputStreamWriter out = null;
        BufferedWriter buffer = null;
        try {
            out = new OutputStreamWriter(output);
            buffer = new BufferedWriter(out);
            buffer.write(text);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                if (buffer != null)
                    buffer.close();
                if (out != null)
                    out.close();
                if (output != null)
                    output.close();
            } catch (Exception e) {
            }
        }
        return true;
    }
}

Related

  1. writeFile(File f, String content)
  2. writeFile(File file, String content)
  3. writeFile(File file, String content)
  4. writeFile(File file, String content, String encoding)
  5. writeFile(File file, String text)
  6. writeFile(OutputStream output, String text)
  7. writeFile(String file, T data, boolean append)
  8. writeFile(String fileName, String content)
  9. writeFile(String fileName, String text)