/** * @author lautturi.com * Java example: how to append a string to the end of file in java */ import java.util.*; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; public class Lautturi { public static void main(String[] args) { try { Path filePath = Paths.get("C:/", "temp", "test.txt"); Files.write(filePath, "appended text".getBytes(), StandardOpenOption.APPEND); // or using writeString (jdk 11) //Files.writeString(filePath, "appended text", StandardOpenOption.APPEND); } catch (IOException e) { //exception handling left as an exercise for the reader e.printStackTrace(); } } }Source:wwal.wutturi.com