Android Text File Write saveFile(String content, File file)

Here you can find the source of saveFile(String content, File file)

Description

Saves the content String to the specified file.

Parameter

Parameter Description
content a parameter
file a parameter

Exception

Parameter Description
IOException thrown if an I/O error occurs opening or creating the file

Declaration

public static void saveFile(String content, File file)
        throws IOException 

Method Source Code

//package com.java2s;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;

public class Main {
    /**/*  ww w  . ja  v a2  s .  c  o  m*/
     * The character set. UTF-8 works good for windows, mac and Umlaute.
     */
    private static final Charset CHARSET = Charset.forName("UTF-8");

    /**
     * Saves the content String to the specified file.
     * 
     * @param content
     * @param file
     * @throws IOException thrown if an I/O error occurs opening or creating the file
     */
    public static void saveFile(String content, File file)
            throws IOException {
        BufferedWriter writer = Files.newBufferedWriter(file.toPath(),
                CHARSET);
        writer.write(content, 0, content.length());
        writer.close();
    }
}

Related

  1. writeToFile(String content, String filePath)
  2. writeToFile(String sb, String directory, String fileName)
  3. writeToFile(String textToWrite, String fileName)
  4. writeToFile(StringBuffer sb, String directory, String fileName)
  5. writeToFile(final String path, final String content)
  6. writeFileSdcard(File file, String message)
  7. writeFile(String filepath, String text)
  8. writeStringToFile(String text, String filePath)
  9. writeToSDFile(String directory, String file_name, String text)