Here you can find the source of writeTextFile(String string, String fileName)
Parameter | Description |
---|---|
string | text to be written |
fileName | file name specified |
public static File writeTextFile(String string, String fileName)
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main{ public static final String tmpdir = System .getProperty("java.io.tmpdir") + File.separator; /**/* w w w . j av a 2 s . c om*/ * write text to a specified text file store in temporary path * @param string text to be written * @param fileName file name specified * @return text file contains the text */ public static File writeTextFile(String string, String fileName) { try { File file = new File(FileUtil.tmpdir + fileName + ".txt"); FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); osw.write(string); osw.flush(); osw.close(); fos.close(); return file; } catch (IOException e) { e.printStackTrace(); } return null; } }