Java FileWriter Write saveSimpleTextFile(String data, String path, String filename)

Here you can find the source of saveSimpleTextFile(String data, String path, String filename)

Description

save Simple Text File

License

Open Source License

Parameter

Parameter Description
data simple text data with no format.
path path which file be stored.
filename file's name.

Exception

Parameter Description
IOException an exception

Declaration

public static void saveSimpleTextFile(String data, String path, String filename) throws IOException 

Method Source Code


//package com.java2s;

import java.io.File;

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

public class Main {
    /**/*from   ww w  .ja va 2  s. c om*/
     * 
     * @author Marquis
     * @Create Date: 2008-3-29
     * @param data
     *            simple text data with no format.
     * @param path
     *            path which file be stored.
     * @param filename
     *            file's name.
     * @throws IOException
     */
    public static void saveSimpleTextFile(String data, String path, String filename) throws IOException {
        File file;
        if ("".equals(path) || path == null) {
            // Save file in current folder
            file = new File(filename);
        } else {
            // Save file in path
            makeDirs(path);
            file = new File(path + File.separator + filename);
        }
        saveSimpleTextFile(data, file);
    }

    /**
     * Save file in current path
     * 
     * @author Marquis
     * @Create Date: 2008-3-29
     * @param data
     *            simple text data with no format.
     * @param filename
     *            file's name.
     * @throws IOException
     */
    public static void saveSimpleTextFile(String data, String filename) throws IOException {
        saveSimpleTextFile(data, null, filename);
    }

    /**
     * 
     * @author Marquis
     * @Create Date: 2008-3-29
     * @param data
     *            simple text data with no format.
     * @param file
     *            file which be created and saved.
     * @throws IOException
     */
    public static void saveSimpleTextFile(String data, File file) throws IOException {
        FileWriter out;
        out = new FileWriter(file);
        out.write(data);
        out.close();
    }

    /**
     * create dirPath
     * 
     * @author Marquis
     * @Create Date: 2008-1-22
     * @param dirPath
     * @return
     */
    public static boolean makeDirs(String dirPath) {
        return new File(dirPath).mkdirs();
    }
}

Related

  1. saveMetaClassToFile(File baseDir, String clazzDef, String metaPackageName, Class fromClazz)
  2. saveMetadata(Map metadata, File file)
  3. saveModelInFile(final String model, final String filename)
  4. savePValue2File(double[] pValue, String fileName)
  5. saveSeqAln(String[] alnSequences, String filePath)
  6. saveStats(String filename, String log)
  7. saveString(File filename, String content)
  8. saveString(String filePath, String content)
  9. saveString(String location, String content)