---
title: "How to append text to an existing file in Java"  
description: "How to append text to an existing file in Java"  
author: "Anonymous User"  
published: 2015-08-14  
updated: 2015-08-14  
canonical: https://www.mindstick.com/forum/33417/how-to-append-text-to-an-existing-file-in-java  
category: "java"  
tags: ["java", "file"]  
reading_time: 1 minute  

---

# How to append text to an existing file in Java

I need to append [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) repeatedly to an existing [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) in Java. How do I do that?

## Replies

### Reply by Anonymous User

You can use fileWriter with a true for appending.\

```
try{    String filename= "MyFile.txt";    FileWriter fw = new FileWriter(filename,true); //the true will append the new data    fw.write("add a line\n");//appends the string to the file    fw.close();}catch(IOException ioe){    System.err.println("IOException: " + ioe.getMessage());}
```


---

Original Source: https://www.mindstick.com/forum/33417/how-to-append-text-to-an-existing-file-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
