import java.io.CharConversionException; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * 文件操作 * */ public class TestReadFile { public static void main(String[] args) { FileReader reader =null; try { reader = new FileReader("D:/java笔记/File类目录的使用.txt"); char c = (char)reader.read(); char c2 = (char)reader.read(); System.out.println(""+c+c2); } catch (FileNotFoundException e){ // TODO Auto-generated catch block e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); }finally { try { if(reader!=null){ reader.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
try catch finally return 执行顺序
1. 执行try, catch 给返回值赋值
2. 执行 finally
3. return