Android Text File Write writeToFile(String content, String filePath)

Here you can find the source of writeToFile(String content, String filePath)

Description

write To File

Declaration

public static void writeToFile(String content, String filePath)
            throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

import java.io.PrintWriter;

public class Main {
    public static void writeToFile(String content, String filePath)
            throws IOException {
        File file = createFile(filePath);
        FileWriter fw = new FileWriter(file, true);
        PrintWriter pWriter = new PrintWriter(new BufferedWriter(fw));
        pWriter.println(content);//from   w  w  w .ja  v a2 s .  com
        pWriter.close();
        fw.close();
    }

    /** Procedure for creating a File */
    public static File createFile(String path) {
        File file = new File(path);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return file;
    }
}

Related

  1. writeTextFile(String path, String text)
  2. writeTextFile(String string, String fileName)
  3. writeTextToFile(String file, String text)
  4. writeToFile(File file, String content)
  5. writeToFile(File target, String s, String charSet)
  6. writeToFile(String sb, String directory, String fileName)
  7. writeToFile(String textToWrite, String fileName)
  8. writeToFile(StringBuffer sb, String directory, String fileName)
  9. writeToFile(final String path, final String content)