Discuss the relationship between some of the common file cla

Discuss the relationship between some of the common file classes in the Java API, the types of exceptions that can be thrown, and the best ways to handle the possible exceptions.

Solution

Common Files classes in java listed below:
1. Byte Streams class
      a. FileInputStrream ---It throws IOException
      b.FileOutputStream ---It Throws IOException
2. Character Streams class
      a. FileReader ---It Throws IOEception
      b. FileWriter ---It throws IOException
    
3. Buffered Stream
     a. BufferedReader ---It Throws IOEception
     b. BufferedWriter ---It Throws IOEception
     c. BufferedInputStream ---It Throws IOEception
     d. BufferedOutputStream ---It Throws IOEception
4. Data Streams
     a. DataInputStream ---It Throws IOEception
     b.DataOutputStream ---It Throws IOEception
5. Object Stream
     a. ObjectInputStream --it throws ClassNotFoundException
     b. ObjectOutputStream --it throws ClassNotFoundException


They can also Throw FileNotFoundException

Best solution is use try and catch block for catching exception
If you want to catch any speific exception any you can give specific name in catch block
otherwise you can give Exception.

Ex.

try{
....
//code

}catch(FileNotFoundException exception) {

}catch(IOException exception) {

}catch(Exception exception) {

}


If you do not want to handle the exception then you can thow the exception using throws keyword

Thanks a lot

Discuss the relationship between some of the common file classes in the Java API, the types of exceptions that can be thrown, and the best ways to handle the po

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site