Java Program on File Handling using Character Stream
Free Java courses with 37 real-time projects - Learn Java
Program 1
package dataflair; import java.io.*; public class TestWriter { public static void main(String args[])throws IOException { File F=new File("c://dataflairfile/student.txt"); FileWriter fw=null; try { fw=new FileWriter(F,true); char ch='D'; fw.flush(); fw.write(ch); System.out.println("File created......"); } finally { fw.close(); } } }
Program 2
package dataflair; import java.io.*; public class TestWriter1 { public static void main(String[] args) throws IOException { File F=new File("c://dataflairfile/student.txt"); FileWriter fw=null; try { fw=new FileWriter(F); String str="Data Flair Free Courses... with free certification..."; fw.flush(); char ch[]; ch=str.toCharArray(); fw.write(ch); // char ch; // for(int i=0;i<str.length();i++) // { // ch=str.charAt(i); // fw.write(ch); // } System.out.println("File created......"); } finally { fw.close(); } } }
Did we exceed your expectations?
If Yes, share your valuable feedback on Google