<<< Try with resources | Index | Common Exception methods >>> |
A method that catches two types of exceptions and automatically closes the specified resource
public static String readFirstLine( String path ) { try ( RandomAccessFile in = new RandomAccessFile( path, "r" ) ) { String line = in.readLine(); // may throw // IOException return line; } catch ( FileNotFoundException ex ) { System.out.println( "File not found" ); return null; } catch ( IOException ex ) { System.out.println( "I/O error occurred" ); return null; } }
<<< Try with resources | Index | Common Exception methods >>> |