Monday, 8 February 2016

How to write data to a text file

How to write data to a text file:
========================
package files;

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

public class FileWriteDemo {

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

File file = new File("D:\\ramesh\\sampleproject\\src\\files\\abc.txt");

file.createNewFile();

FileWriter fileWriter = new FileWriter(file);

BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

bufferedWriter.write("hello selenium");

bufferedWriter.newLine();

bufferedWriter.write("we are experts");

bufferedWriter.flush();
}

}

No comments:

Post a Comment