FileNotFoundException

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

What might go wrong inside the outer try{} block which would cause an exception?

Answer:

(1) One of the files might not open. (2) There might be an error in reading from a file. (3) There might be an error in writing to a file. (4) One of the files might not close.

FileNotFoundException

All of those problems are IOExceptions so the outer try{} could catch them all with one catch{} block. But this one block would not be very specific about which type of error it caught. The constructors for FileInputStream and FileOutputStream throw FileNotFoundException when there is a problem. Its catch{} block should preceed the one for IOException.

Here is the program so far:

    . . . . 
try
{
  instr = 
  outstr = 
  try
  {
  }
  catch ( EOFException  eof )
  {
  }

}

catch( ______________________ )
{
}

catch( ______________________ )
{
}

QUESTION 19:

Fill in the blanks.