Write java program to read and write character using file.
import java.io.*;
public class Main
{
public static void main(String[] args) {
try{
FileWriter out=new FileWriter("output.txt");
out.write("Hello world.");
out.close();
}
catch(Exception e){
System.out.println(e);
}
try{
FileReader in=new FileReader("output.txt");
int i;
while((i=in.read())!=-1)
System.out.print((char)i);
in.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
Output
Comments
Leave a comment