Android Text File Write writeNewFile(String filePath, String fileContents)

Here you can find the source of writeNewFile(String filePath, String fileContents)

Description

write New File

Declaration

public static void writeNewFile(String filePath, String fileContents) 

Method Source Code

//package com.java2s;

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

import java.io.FileWriter;

import android.util.Log;

public class Main {
    private static final String TAG = "Helpers";

    public static void writeNewFile(String filePath, String fileContents) {
        File f = new File(filePath);
        if (f.exists()) {
            f.delete();//ww w  .  j a v  a 2s.  c om
        }

        try {
            // Create file
            FileWriter fstream = new FileWriter(f);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(fileContents);
            //Close the output stream
            out.close();
        } catch (Exception e) {
            Log.d(TAG, "Failed to create " + filePath + " File contents: "
                    + fileContents);
        }
    }
}

Related

  1. writeFile(String filepath, String text)
  2. writeStringToFile(String text, String filePath)
  3. writeToSDFile(String directory, String file_name, String text)
  4. writeFileEnd(String filepath, String text)
  5. WriteFile(String file, String message)
  6. writeStringToFile(File file, String data)
  7. writeTextFile(File file, String str)
  8. writeTextFile(File file, String[] strArray)