Here you can find the source of saveToFile(String fileName, String str)
public static void saveToFile(String fileName, String str) throws IOException
//package com.java2s; /* LemonTree //from ww w .j a v a 2s . c o m * * Copyright (c) 2012 Tom Michoel, Eric Bonnet * * LemonTree is free software, released under the terms of the GNU general * Public License (GPL) v2. See LICENSE file for details. * */ import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { public static void saveToFile(String fileName, String str) throws IOException { File f = new File(fileName); if (!f.exists()) { if (f.getParent() != null) { new File(f.getParent()).mkdirs(); } f.createNewFile(); } FileWriter fw = new FileWriter(f); fw.write(str); fw.close(); } }