Java FileWriter Write saveToFile(String fileName, String str)

Here you can find the source of saveToFile(String fileName, String str)

Description

save To File

License

Open Source License

Declaration

public static void saveToFile(String fileName, String str) throws IOException 

Method Source Code


//package com.java2s;
/* LemonTree //from  ww w  .j  a  v a 2s . c o  m
 * 
 * Copyright (c) 2012 Tom Michoel, Eric Bonnet 
 * 
 * LemonTree is free software, released under the terms of the GNU general
 * Public License (GPL) v2. See LICENSE file for details.  
 *
*/

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

public class Main {
    public static void saveToFile(String fileName, String str) throws IOException {
        File f = new File(fileName);
        if (!f.exists()) {
            if (f.getParent() != null) {
                new File(f.getParent()).mkdirs();
            }
            f.createNewFile();
        }
        FileWriter fw = new FileWriter(f);
        fw.write(str);
        fw.close();
    }
}

Related

  1. saveToFile(File file, String string)
  2. saveToFile(File file, String text)
  3. saveToFile(List lines, String pathname)
  4. saveToFile(List list, String filename, boolean append)
  5. saveToFile(String fileName, String resultStr)
  6. saveToFile(String location, File tempFile)
  7. saveToFile(String path, String line)
  8. saveToFile(String prefix, Reader input)
  9. saveToJson(Object object, String file)