Here you can find the source of writeFileByLine(String content, String filename, boolean append)
public static void writeFileByLine(String content, String filename, boolean append)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; public class Main { public static void writeFileByLine(String content, String filename, boolean append) { File file = new File(filename); String pathname = new File(filename).getParent(); if (!new File(pathname).exists()) { new File(pathname).mkdirs(); }/*from w w w. ja v a 2 s .com*/ PrintWriter writer = null; try { writer = new PrintWriter(new FileOutputStream(file, append)); writer.print(content); writer.println(); writer.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (Exception e1) { e1.printStackTrace(); } } } } public static void writeFileByLine(String content, String filename) { File file = new File(filename); PrintWriter writer = null; try { writer = new PrintWriter(new FileOutputStream(file)); writer.print(content); writer.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (Exception e1) { e1.printStackTrace(); } } } } }