import java.io.*;
public class Mine
{
public static void main(String args[])
{
Mine m=new Mine();
System.out.println(m.amethod());
}
public int amethod()
{
try{
FileInputStream dis=new FileInputStream("Hello.txt");
}
catch(FileNotFoundException fne)
{
System.out.println("No such file found");
return -1;
}
catch(IOException ioe)
{
}
finally
{
System.out.println("Doing finally");
}
return 0;
}为啥不是NO such file found,-1,Doing finally,而输出No such file found,Doing finally,-1?
return -1;不是先执行完这里再去执行finally?
如果直接return了 那finally不就不能执行了吗!
try{
FileInputStream dis=new FileInputStream("Hello.txt");
}
catch(FileNotFoundException fne)
{
System.out.println("No such file found");//首先输出这里
return -1;//这里不是完全的返回,而是已经定好了要返回得值,随时准备回去
}
catch(IOException ioe)
{
}
finally
{
System.out.println("Doing finally");//这里是方法返回之前的最后一步
}
return 0;
LZ查看finally的用法