How to append text to an existing file in Java
I need to append text repeatedly to an existing file in Java. How do I do that? Are you doing this for logging purposes? If so there are several libraries for this . Two of the most popular are Log4j and Logback . Java 7+ If you just need to do this one time, the Files class makes this easy: try { Files.write(Paths.get("myfile.txt"), "the text".getBytes(), StandardOpenOption.APPEND); }catch (IOException e) { //exception handling left as an exercise for the reader } Careful : The above approach will throw a NoSuchFileException if the file does not already exist. It also does not append a