Why am I getting java.io.FileNotFoundException in the following program?
import java.io.*;
class FisDemo {
public static void main(String[] args)throws IOException{
FileInputStream fis=new FileInputStream("abc.txt");
/* Here we are accessing file abc.txt statically. i.e abc.txt must exist in current class directory */
int data;
while(( data=fis.read())!=-1){
System.out.println((char)data);
// here we are casting, because return type of read() is int
}
}
}
The reason is abc.txt is not present(in the current directory).
Specify the full name of the file
And yes is the answer for your second question.