Java Program to write a file in append mode


In this program, You will learn how to write a file in append mode in java.


FileWriter fw = new FileWriter("abc.txt", true);

fw.write(str);

Example: How to write a file in append mode in java.

import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

class Test {

    public static void main(String args[]) {

        String str;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter String value :");
        str = sc.nextLine();

        try {
            FileWriter fw = new FileWriter("abc.txt", true);
            fw.write(str);
            fw.close();

        } catch (IOException e) {
            System.out.println(e);
        }

        System.out.println("\nSuccessfully Done");
    }
}

Output:

Enter String value :John Smith
Successfully Done

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.