Sunday, April 29, 2018

Write the data in a file using BufferedWriter !!

Using BufferedWriter:
  1. import java.io.File;
  2. import java.io.FileWriter;
  3. import java.io.BufferedWriter;
  4. import java.io.IOException;

  5. public class WriteByBufferedWriterExe {

  6. public static void main(String[] args) throws IOException {
  7. String contents = "writing data using BufferedWriter. Isn't it interesting !!)";

  8. File file = new File("D:\\data1.txt");
  9. FileWriter fw = new FileWriter(file);
  10. BufferedWriter bw = new BufferedWriter(fw);

  11. for (int i = 0; i < 5; i++) {
  12. bw.write(contents);
  13. bw.newLine(); // bw.append("\n");
  14. }
  15. bw.close();
  16. }
  17. }


Output:
writing data using BufferedWriter. Isn't it interesting !! :)
writing data using BufferedWriter. Isn't it interesting !! :)
writing data using BufferedWriter. Isn't it interesting !! :)
writing data using BufferedWriter. Isn't it interesting !! :)
writing data using BufferedWriter. Isn't it interesting !! :)

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...