In: Computer Science
*OBJECT ORIENTED PROGRAMMING*
GOAL: will be able to throw and catch exceptions and create multi-threaded programs.
Part I
Part II
import java.io.*;
class ExceptionExample{
public static void main(String args[]){
FileInputStream fis = null;
//FileInputStream throws
//FileNotFoundException which is
// a checked exception.
fis = new FileInputStream("D:/abc.txt");
int i;
//read() method of FileInputStream
//class also throws an IOException.
while(( i = fis.read() ) != -1 ){
System.out.println((char)i);
}
//close() method used for
//close the file input stream
//it throws an IOException.
fis.close();
}
}
import java.io.*;
class ExceptionExample{
public static void main(String args[]){
FileInputStream fis = null;
try{
fis = new FileInputStream("D:/abc.txt");
}
catch(FileNotFoundException fn){
System.out.println("The file is not present at given path");
}
int i;
try{
while(( i = fis.read() ) != -1 ){
System.out.println((char) i);
}
fis.close();
}
catch(IOException ie){
System.out.println("IOException occured: " +ie);
}
}
}