Here you can find the source of writeToFile(String sb, String directory, String fileName)
public static void writeToFile(String sb, String directory, String fileName)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static void writeToFile(String sb, String directory, String fileName) {//from w ww . ja v a 2 s . c o m File dir = new File(directory); dir.mkdirs();//create necessary directory if (!directory.endsWith("/")) { directory = directory + "/"; } File out = new File(directory + fileName); System.out.println(directory + fileName); try { Writer fw = new OutputStreamWriter(new FileOutputStream(out, false), "UTF-8"); try { fw.write(sb); fw.close(); } catch (IOException e) { e.printStackTrace(); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } } public static void writeToFile(StringBuffer sb, String directory, String fileName) { writeToFile(sb.toString(), directory, fileName); } }