Posted inTechno Guide

Read Character from File Handling Character One by one Reading

A Program in Java for mouse event handling using Methods()

Can you generate a logic to read characters from File Handling Character One by one? If you can generate it then it will be easier to you to do that.

package handlefile;
import java.io.*;
import java.util.Scanner;
public class SimpleFile 
 {
    public static void main(String[] args) 
    {
    Scanner scanner = new Scanner(System.in); try 
    {
    FileInputStream fin = new FileInputStream("File1.txt");
    FileOutputStream fout= new FileOutputStream("File2.txt");
    int ch;
  while ((ch=fin.read())!= -1)
  {
     fout.write(ch);
   }
    System.out.println("File copying successful"); 
    fin.close();
    fout.close();
   }catch(Exception ex){
    System.err.print("The file cannot be created.");
    } 
  }
}

Puskar Nath, a 19-year-old science stream graduate from Himalayan Whitehouse International College, is a budding author with a passion for sharing his thoughts and ideas through writing.

Leave a Reply

Your email address will not be published. Required fields are marked *