Java Text File Save writeFile(String path, String content)

Here you can find the source of writeFile(String path, String content)

Description

write File

License

LGPL

Declaration

public static boolean writeFile(String path, String content) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.*;

public class Main {
    public static boolean writeFile(String path, String content) {
        boolean successed = false;
        OutputStream fos = null;//from   ww w. j a  va2s  .com
        Writer osw = null;
        try {
            File file = new File(path);
            if (!file.exists()) {
                file.getParentFile().mkdirs();
                file.createNewFile();
            }
            fos = new FileOutputStream(file);
            osw = new OutputStreamWriter(fos, "UTF-8");

            String newContent = content != null ? content : "";
            osw.write(newContent);

            successed = true;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                osw.close();
                fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return successed;
    }
}

Related

  1. writeFile(List strList, String fileFullPath)
  2. writeFile(List txtList, String MyFilePath)
  3. writeFile(String file, String content)
  4. writeFile(String file, String text)
  5. writeFile(String filePath, List lines)
  6. writefile(String path, String content)
  7. writefile(String path, String content)
  8. writeFile(String path, String content)
  9. writefile(String path, String content, boolean append)