Android Text File Write writeFile(OutputStream output, String text)

Here you can find the source of writeFile(OutputStream output, String text)

Description

write File

Declaration

public static boolean writeFile(OutputStream output, 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   w  w  w . ja  v a 2  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 file, String content)
  2. writeFile(File file, String content)
  3. writeFile(File file, String content, String encoding)
  4. writeFile(File file, String text)
  5. writeFile(File out, String text)
  6. writeFile(String file, T data, boolean append)
  7. writeFile(String fileName, String content)
  8. writeFile(String fileName, String text)
  9. writeFile(String fileName, String text, boolean isAppend)