FileReader and FileWriter in Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Random Posts

FileReader and FileWriter in Java

Share This

Source code
package com.t4b.test; import java.io.FileReader; public class FileReaderTest { public static void main(String[] args) { try { FileReader fr = new FileReader("test.txt"); int i; while ((i = fr.read()) != -1) System.out.print((char) i); fr.close(); } catch (Exception e) { e.printStackTrace(); } } }


Source code
package com.t4b.test; import java.io.FileWriter; public class FileWriterTest { public static void main(String[] args) { try { FileWriter fw = new FileWriter("test.txt"); fw.write("Hello World!"); fw.close(); } catch (Exception e) { System.out.println(e); } } }

Happy Exploring!

No comments:

Post a Comment