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

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...