When you work with I/O in Java most of the time you have to handle IOException which can occur any time when you read/write or even close the stream.
You have to put your sensitive block in a try//catch block and handle the exception here.
For example:
try{
// All your I/O operations
}
catch(IOException ioe){
//Handle exception here, most of the time you will just log it.
}
Resources: