Here you can find the source of writeToFile(String outputFilePath, String generated)
public static void writeToFile(String outputFilePath, String generated)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.charset.Charset; public class Main { public static void writeToFile(String outputFilePath, String generated) { File outputFile = new File(outputFilePath); //create dirs if not exist if (outputFile.getParent() != null && !new File(outputFile.getParent()).exists()) { File parent = new File(outputFile.getParent()); parent.mkdirs();//from w w w .j av a 2s .c om } //write try (PrintWriter output = new PrintWriter(outputFile, Charset.forName("UTF-8").name())) { output.print(generated); } catch (FileNotFoundException | UnsupportedEncodingException e) { System.out.println("Error while writing to file :" + e); throw new RuntimeException(e); } } }