Sunday, 21 August 2016

How To Append Text Into File In Java


//step 1. take path of file where you have to append text.
//step 2. create file object by keeping path in constructor of File
//step 3. create filewriter object to write the byte into file and true value means it will append text into file.
//step4. create BufferedWriter for better performance
//step 5. use append method and in last dont forget to close strem

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class AppendText {

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

                        String path = "D:/neeraj.txt";

                        File file = new File(path);

                        FileWriter fw = new FileWriter(file, true);

                        BufferedWriter bw = new BufferedWriter(fw);

                        fw.append(" how are you neeraj");
                        bw.close();

                        System.out.println("written");

            }


}

No comments:

Post a Comment