Here you can find the source of appendToFile(String fileName, String content)
Parameter | Description |
---|---|
fileName | The name of file to append to. Must be in data folder.<br/> File will be created if it doesn't exist. |
content | The content to write |
true
, if appended successfully, false
otherwise
public static boolean appendToFile(String fileName, String content)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**/*from w w w . j a va 2s . c om*/ * * @param fileName The name of file to append to. Must be in data folder.<br/> * File will be created if it doesn't exist. * @param content The content to write * @return <code>true</code>, if appended successfully, <code>false</code> otherwise */ public static boolean appendToFile(String fileName, String content) { return appendToFile(new File(getOutputFolder() + fileName), content); } /** * @param file The file to append in * @param content The content to write * @return <code>true</code>, if appended successfully, <code>false</code> otherwise */ public static boolean appendToFile(File file, String content) { try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));) { out.println(content); } catch (IOException e) { System.out.println("Exception while writing to file " + file.getName()); e.printStackTrace(); return false; } return true; } public static String getOutputFolder() { return System.getProperty("user.dir") + "/data/"; } }