Sunday, April 29, 2018

Write the data using PrintWriter in java !!

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

  5. public class WriteByPrintWriterExe {
  6. public static void main(String[] args) throws IOException {
  7. File file = new File("D:\\data1.txt");
  8. FileWriter fw = new FileWriter(file);
  9. PrintWriter pw = new PrintWriter(fw);

  10. for (int i = 0; i < 5; i++) {
  11. pw.write("using PrintWriter !!");
  12. pw.append("\n");
  13. }
  14. pw.close();
  15. }
  16. }
Output:
using PrintWriter !!
using PrintWriter !!
using PrintWriter !!
using PrintWriter !!
using PrintWriter !!

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