Here you can find the source of writeStringToFile(String s, File file)
public static void writeStringToFile(String s, File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static void writeStringToFile(String s, File file) throws IOException { OutputStream out = null;//from w w w . j av a2 s . c o m try { out = new FileOutputStream(file); out.write(s.getBytes()); } finally { forceClosed(out); } } public static void forceClosed(InputStream stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } public static void forceClosed(OutputStream stream) { if (stream != null) { try { stream.close(); } catch (IOException e) { } } } }