Reply to comment

Append String to Text File in Java

Tagged:  
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class AppendToFile {

	public static void main(String[] args) throws IOException {

		String path = "/home/jr/Desktop/file1.txt";
		String text = "add this text";
		
		File file = new File(path);
		FileWriter writer = new FileWriter(file, true);

		writer.append(text);
		writer.close();
	}
}

Reply

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
19 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.