Here you can find the source of writeStringToFile(String filename, String string, boolean overwrite)
Parameter | Description |
---|---|
filename | a parameter |
strings | a parameter |
overwrite | a parameter |
public static void writeStringToFile(String filename, String string, boolean overwrite)
//package com.java2s; //License from project: LGPL import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; public class Main { /**/*from ww w . ja va 2s.co m*/ * @param filename * @param strings * @param overwrite */ public static void writeStringToFile(String filename, String string, boolean overwrite) { File destFile = new File(filename); try { if (destFile.exists()) { if (overwrite) destFile.delete(); else return; } destFile.createNewFile(); Writer outputStream = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(destFile), "UTF-8")); outputStream.write(string); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }