import java.io.*;
class ShowFile {
public static void main(String args[])throws IOException {
int i;
FileInputStream fin;
try {
fin=new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;//它在这里有什么作用呢,为什么不能注释了呢
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: ShowFile File ");
return;//它在这里有什么作用呢,为什么不能注释了呢
}
do{
i=fin.read();
if(i!=-1)System.out.print((char) i);
}while(i!=-1);
fin.close();
}
}
class ShowFile {
public static void main(String args[])throws IOException {
int i;
FileInputStream fin;
try {
fin=new FileInputStream(args[0]);
} catch(FileNotFoundException exc) {
System.out.println("File Not Found");
return;//它在这里有什么作用呢,为什么不能注释了呢
} catch(ArrayIndexOutOfBoundsException exc) {
System.out.println("Usage: ShowFile File ");
return;//它在这里有什么作用呢,为什么不能注释了呢
}
do{
i=fin.read();
if(i!=-1)System.out.print((char) i);
}while(i!=-1);
fin.close();
}
}
就是执行了也不出现错误的
所以用return返回
只不过catch后的语句应该不会执行。
ArrayIndexOutOfBoundsException是RuntimeException的子类属于未检查异常,他们要么是不可控制的(Error)或者是我们首先就应该避免他们发生(RuntimeException)
如果注释掉,就会执行
do{
i=fin.read();
if(i!=-1)System.out.print((char) i);
}while(i!=-1);
可以把它修改一下.
do{
if (fin != null)
i=fin.read();
if(i!=-1)System.out.print((char) i);
}while(i!=-1); if (fin != null)
fin.close();