import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.net.URI;
import org.eclipse.core.filesystem.EFS;
private static final int BUFFER_SIZE = 8192;
/**
+ * write text into given file
+ */
+ public static void writeTextFile(File file, String text, String encoding) throws IOException {
+ BufferedWriter out = null;
+
+ if (encoding == null) { // if encoding is not set then use default encoding
+ encoding = System.getProperty("file.encoding");
+ }
+
+ try {
+ out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding), BUFFER_SIZE);
+ out.write(text.toCharArray(), 0, text.length());
+ out.flush();
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
+ /**
* read text from given file
*/
public static String readTextFile(File file, String encoding) throws IOException {