Java Text File Save WriteFile(String sFileName, String content)

Here you can find the source of WriteFile(String sFileName, String content)

Description

Write content to file

License

Open Source License

Parameter

Parameter Description
sFileName file name
content the content that need to write to file

Return

true if write success or false if write fail

Declaration

public static boolean WriteFile(String sFileName, String content) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from w  ww  .j  a  va2s . co  m*/
     * Write content to file
     * 
     * @param sFileName
     *            file name
     * @param content
     *            the content that need to write to file
     * @return true if write success or false if write fail
     */
    public static boolean WriteFile(String sFileName, String content) {
        FileWriter fw = null;

        try {
            fw = new FileWriter(sFileName, true);

            fw.write(content);
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
            // if abnormal then return false
            return false;
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e1) {
                }
            }
        }

        // if finish writing then return true
        return true;
    }
}

Related

  1. writeFile(String path, String text)
  2. writeFile(String path, String text, boolean orverWite)
  3. writeFile(String path, Vector contents)
  4. writeFile(String pContent, String pPath)
  5. writeFile(String ruta, String nombre, byte[] archivo)
  6. writeFile(String sFileName, String sContent)
  7. writeFile(String sName, String data, String encoding)
  8. writeFile(String str, File f)
  9. writeFile(String str, String filename, boolean append)