package Demo_exception;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FinallyTest {
public static void main(String[] args) {
FileInputStream fis=null;
System.out.println("---关闭文件---");
try{
fis=new FileInputStream("file.text");
}catch(FileNotFoundException e){
System.out.println("catch:文件不存在异常!");
e.printStackTrace();
}finally{
System.out.println("执行finally语句");
try{
if(fis!=null){
fis.close();
}
}catch(IOException e){//是否被其他程序读写
System.out.println("文件关闭异常");
e.printStackTrace();
}
}
}
}
Java学习笔记32:finally语句
最新推荐文章于 2024-01-20 15:04:51 发布