Here you can find the source of saveSimpleTextFile(String data, String path, String filename)
Parameter | Description |
---|---|
data | simple text data with no format. |
path | path which file be stored. |
filename | file's name. |
Parameter | Description |
---|---|
IOException | an exception |
public static void saveSimpleTextFile(String data, String path, String filename) throws IOException
//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(); } }