Here you can find the source of writeToFile(String content, String filePath)
public static void writeToFile(String content, String filePath) throws IOException
//package com.java2s; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class Main { public static void writeToFile(String content, String filePath) throws IOException { File file = createFile(filePath); FileWriter fw = new FileWriter(file, true); PrintWriter pWriter = new PrintWriter(new BufferedWriter(fw)); pWriter.println(content);//from w w w .ja v a2 s . com pWriter.close(); fw.close(); } /** Procedure for creating a File */ public static File createFile(String path) { File file = new File(path); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return file; } }