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

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

Description

write To File

License

Apache License

Declaration

public static void writeToFile(String 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 .  ja  v a 2 s  . c o  m
        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. writeTextFile(String string, String fileName)
  2. writeTextToFile(String file, String text)
  3. writeToFile(File file, String content)
  4. writeToFile(File target, String s, String charSet)
  5. writeToFile(String content, String filePath)
  6. writeToFile(String textToWrite, String fileName)
  7. writeToFile(StringBuffer sb, String directory, String fileName)
  8. writeToFile(final String path, final String content)
  9. saveFile(String content, File file)