Importjava.io.CharConversionException;Importjava.io.FileNotFoundException;ImportJava.io.FileReader;Importjava.io.IOException;/*** File Operation **/ Public classTestreadfile { Public Static voidMain (string[] args) {FileReader reader=NULL; Try{Reader=NewFileReader ("D:/java Notes/file class directory use. txt"); Charc = (Char) Reader.read (); CharC2 = (Char) Reader.read (); System.out.println ("" +c+C2); } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }finally { Try { if(reader!=NULL) {reader.close (); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } } }}
Try catch finally return execution order
1. Perform a try, catch to assign a value to the return value
2. Execute finally
3. Return
Use of Try catch in Java for file-related operations