Here you can find the source of writeToFile(String filename, String fileContents)
private static void writeToFile(String filename, String fileContents)
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.charset.StandardCharsets; public class Main { private static void writeToFile(String filename, String fileContents) { Writer writer = null;/*from www . j a va 2s . co m*/ try { writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(filename), StandardCharsets.US_ASCII)); writer.write(fileContents); } catch (IOException e) { e.printStackTrace(); } finally { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } }