Sunday, April 29, 2018

Write same data multiple times in a file using FileWriter class !!

Using FileWriter:
  1. import java.io.File;
  2. import java.io.FileWriter;

  3. public class WriteByFileWriterExe {

  4. public static void main(String[] args) throws Exception {
  5. File file = new File("D:\\data1.txt");
  6. FileWriter fw = new FileWriter(file);

  7. for (int i = 0; i < 5; i++) {
  8. fw.write("using FileWriter !!");
  9. fw.append("\n");
  10. }
  11. fw.close();
  12. }
  13. }
Output:

using FileWriter !!
using FileWriter !!
using FileWriter !!
using FileWriter !!
using FileWriter !!

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...