Here you can find the source of appendToFile(final File file, final String contents)
Parameter | Description |
---|---|
file | the file to save to. |
contents | String to append to file. |
public static void appendToFile(final File file, final String contents) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**//from w w w. j a v a 2 s . c om * Appends the contents String to a file. * * @param file the file to save to. * @param contents String to append to file. * @exception IOException if there is an error opening or writing to file. */ public static void appendToFile(final File file, final String contents) throws IOException { try (FileOutputStream fos = new FileOutputStream(file, true)) { fos.write(contents.getBytes()); } } }