Here you can find the source of saveTextToFile(String fileName, String content)
public static void saveTextToFile(String fileName, String content)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void saveTextToFile(String fileName, String content) { if (content == null) { System.out.println("File not saved, content is null " + fileName); return; }/* w w w. j ava 2 s. com*/ FileOutputStream fop = null; File file; try { file = new File(fileName); fop = new FileOutputStream(file); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } // get the content in bytes byte[] contentInBytes = content.getBytes(); fop.write(contentInBytes); fop.flush(); fop.close(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fop != null) { fop.close(); } } catch (IOException e) { e.printStackTrace(); } } } }