Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { /** * Save text to certain file. * @param target_file The file to load the text. */ public static boolean saveFile(File target_file, String text) { boolean result = false; FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(target_file); //Charset: UTF-8 (default) fileOutputStream.write(text.getBytes()); result = true; } catch (IOException e) { e.printStackTrace(); } finally { if (fileOutputStream != null) { try { fileOutputStream.flush(); fileOutputStream.close(); } catch (IOException e) { } } } return result; } }