Android Text File Write writeToFile(StringBuffer sb, String directory, String fileName)

Here you can find the source of writeToFile(StringBuffer sb, String directory, String fileName)

Description

write To File

License

Apache License

Declaration

public static void writeToFile(StringBuffer sb, String directory,
            String fileName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static void writeToFile(String sb, String directory,
            String fileName) {//from w  ww  .j  av  a  2s.com
        File dir = new File(directory);
        dir.mkdirs();//create necessary directory
        if (!directory.endsWith("/")) {
            directory = directory + "/";
        }
        File out = new File(directory + fileName);
        System.out.println(directory + fileName);
        try {
            Writer fw = new OutputStreamWriter(new FileOutputStream(out,
                    false), "UTF-8");
            try {
                fw.write(sb);
                fw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void writeToFile(StringBuffer sb, String directory,
            String fileName) {
        writeToFile(sb.toString(), directory, fileName);
    }
}

Related

  1. writeToFile(File file, String content)
  2. writeToFile(File target, String s, String charSet)
  3. writeToFile(String content, String filePath)
  4. writeToFile(String sb, String directory, String fileName)
  5. writeToFile(String textToWrite, String fileName)
  6. writeToFile(final String path, final String content)
  7. saveFile(String content, File file)
  8. writeFileSdcard(File file, String message)
  9. writeFile(String filepath, String text)