Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java catch IOException

I think this is basic stuff but i'm not sure what to do. Why do I get IOException never thrown in body of corresponding try statement

public static void main(String[] args)
    {
        File inputFile = null ;

        try
        {
            inputFile = new File("records.txt") ;   
        }
        catch (IOException e)
        {
            System.out.print("file not found!") ;
        }

1 Answers

The File constructor in itself doesn't do very much.

It is not until you actually start doing actual operations that IOExceptions can be thrown.

like image 173
Thorbjørn Ravn Andersen Avatar answered Jul 30 '26 11:07

Thorbjørn Ravn Andersen