Here you can find the source of writeFile(String directory, String content, String fileName, boolean deleteFileBeforeWriting)
public static void writeFile(String directory, String content, String fileName, boolean deleteFileBeforeWriting)
//package com.java2s; /** /* w ww . j a v a 2s. c o m*/ * @author Dimitri Dean DARSEYNE (D3), * Published by Short-Circuit under Creative Commons (CC) Licensing: * Authorship/Paternity, NO Commercial Use, NO Derivative * Please check for more informations: * http://creativecommons.org/licenses/by-nc-nd/2.0/ * * Auteur Dimitri Dean DARSEYNE (D3), * Publi? par Short-Circuit sous license Creative Commons (CC): * Paternit?, PAS d'Utilisation Commerciale, pas de D?riv?s/Modifications * Pour plus d'informations, se rendre sur: * http://creativecommons.org/licenses/by-nc-nd/2.0/fr/ * * @since Short-Circuit 1999 */ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; public class Main { public static void writeFile(String directory, String content, String fileName, boolean deleteFileBeforeWriting) { try { if (deleteFileBeforeWriting) deleteFile(directory + fileName); BufferedWriter out = new BufferedWriter(new FileWriter(directory + fileName, deleteFileBeforeWriting)); out.write(content); //out.newLine(); out.close(); } catch (Exception e) { System.out.println("failed to write query"); } } public static void writeFile(String content, String fileName, boolean deleteFileBeforeWriting) { try { if (deleteFileBeforeWriting) deleteFile(fileName); BufferedWriter out = new BufferedWriter(new FileWriter(fileName, deleteFileBeforeWriting)); out.write(content); //out.newLine(); out.close(); } catch (Exception e) { System.out.println("failed to write query"); } } public static void deleteFile(String fileName) { try { File file2delete = new File(fileName); file2delete.delete(); } catch (Exception e) { System.out.println("failed to write query"); } } }