The problem is that fin is out of scope when it gets to that line. Here are the scopes in your code.
public static HSSFWorkbook loadWorkbook(String fileName){ //start method scope
try{//start try scope
} //end try scope
catch(...) { //start catch scope
}//end catch scope
}//end method scope
A variable is only usable within it's respective scope. Variables instantiated inside of the try scope don't exist outside of that try scope. I would combine your try statements.
If you can't put everything into the same scope you can bring that variable out of the try block. i.e.:
public static HSSFWorkbook loadWorkbook(String fileName){
SmbFileInputStream fin = null;
try{
fin = new SmbFileInputStream(...);
} catch(...) {
}
//do stuff with fin
}
Personally, I would rather put everything in the same scope and implement my own exception class:
public static HSSFWorkbook loadWorkbook(String fileName)throws CustomException{
try{
SmbFileInputStream fin = new SmbFileInputStream(...);
//do stuff with fin
return wb;
} catch(FileNotFoundException f) {
//handle file not found
throw new CustomException("File Not found ...", f);
} catch(IOException io) {
//handle io exception
throw new CustomException("loadWorkBook failed", io);
}
}
Also you shouldn't do this:
try{
SmbFileInputStream fin = new SmbFileInputStream("smb:" + fileName);
} catch(FileNotFoundException e){
SmbFileInputStream fin = new SmbFileInputStream("smb:" + fileName);
//unreachable code
...
}
because if instantiating SmbFileInputStream throws a file not found exception in the try block, then it will definitely throw one in the catch block. Everything after the first line in the catch will never execute.