Here you can find the source of appendLineToTextFile(File file, String line)
Parameter | Description |
---|---|
file | a parameter |
line | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void appendLineToTextFile(File file, String line) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { /**/*from w w w .j a v a2 s. co m*/ * Appends a new line to a text file. If file doesn't exists it is created. * * @param file * @param line * @throws IOException */ public static void appendLineToTextFile(File file, String line) throws IOException { boolean newLine = true; if (!file.exists()) { file.createNewFile(); newLine = false; } FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); if (newLine) { bw.newLine(); } bw.write(line); bw.close(); } }