I'm trying to fetch the data from a text file using FileInputStream but it is not happening Here is the code.
package com.example.ex2;
import java.io.*;
import java.util.*;
public class Input {
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("abc.txt");
int i;
FileInputStream fr;
while((i=fr.read())!=-1)
System.out.println((char)i);
fin.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
The error which i'm getting is : Exception in thread "main" java.lang.Error: Unresolved compilation problem: The local variable fr may not have been initialized I'm using Eclipse.
first , replace this :
while((i=fr.read())!=-1)
with this :
while((i=fin.read())!=-1)
second thing is that you have to check that your class file name match the Class name, another point is that you have to add throws Exception
next to the main method.