import java.io.*; //引进包
class exceptiondemo{public static void main(string arge[])throws IOException //main抛出IO异常
{
FileInputStream fis = null; //声明初始化输入文件流try{ system.out.println("first argument is "+args[0]); //显示你输入的第一个参数
fis = new fileinputstream("text"); //初始化fis,读入 text的文件
system.out.println("content of text is :");
int b;
while((b=fis.read())!=-1) //把 text 的文件内容一个一个char的显示出来
{
system.out.priant((char)b);
}}catch(filenotfoundexception e){ //捕获文件不存在异常 system.out.println(e); //显示异常内容}catch(ioexception e){ //捕获IO异常sysetm.out.println(e);}catch(indexoutofboudsexception e){ //溢出异常system.out.println("closing fileinputstream..");fis.close(); //关文件}else{system.out.println("fileinputstream not open"); }
}
}
}
class exceptiondemo{public static void main(string arge[])throws IOException //main抛出IO异常
{
FileInputStream fis = null; //声明初始化输入文件流try{ system.out.println("first argument is "+args[0]); //显示你输入的第一个参数
fis = new fileinputstream("text"); //初始化fis,读入 text的文件
system.out.println("content of text is :");
int b;
while((b=fis.read())!=-1) //把 text 的文件内容一个一个char的显示出来
{
system.out.priant((char)b);
}}catch(filenotfoundexception e){ //捕获文件不存在异常 system.out.println(e); //显示异常内容}catch(ioexception e){ //捕获IO异常sysetm.out.println(e);}catch(indexoutofboudsexception e){ //溢出异常system.out.println("closing fileinputstream..");fis.close(); //关文件}else{system.out.println("fileinputstream not open"); }
}
}
}
解决方案 »
- ALL 在web.xml中加载applicationContext.xml,来生成bean,为啥总是提示空指针错误
- 反序列化时遇到异常
- java命令行的问题!
- 两个简单问题先来先给分[网络 + string]
- 下面的程序代码是一个同步打枪的实例,子弹的容量是12粒,使用程序来模拟对枪膛的压入和射出操作。请问下面的代码,那里出现问题,然后怎样解决?
- 如何通过java从二进制文件中读取以前用c中fwrite函数写入的一个结构体?
- jsp include标签
- csdn陪我走过了一个年头。从认识她到想到一直到离不开她。。。
- Vector的问题
- 关于Javascript....请高手指点!
- JAVA亂碼的問題﹗
- kunbone(坤坤乖乖),viperasi(viper),sbojuqqk(小猪快跑!) 进来!
跟else配套的if好象我都没看到嘛
class exceptiondemo{
public static void main(String arge[])throws IOException{
FileInputStream fis=null;
try{
System.out.println("first argument is "+arge[0]);
fis = new FileInputStream("text");
System.out.println("content of text is :");
int b;
while((b=fis.read())!=-1){
System.out.println((char)b);
}
}catch(FileNotFoundException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}catch(IndexOutOfBoundsException e){
System.out.println("closing fileinputstream..");
fis.close();
}
System.out.println("fileinputstream not open");
}
}
class exceptiondemo
{
public static void main(String args[])throws IOException
{
FileInputStream fis = null;
try
{
System.out.println("first argument is "+args[0]);
fis = new FileInputStream("text.txt");
System.out.println("content of text is :");
int b;
while((b=fis.read())!= -1)
{
System.out.print((char)b);
}
}
catch(FileNotFoundException e)
{
System.out.println(e);
}
catch(IOException e)
{
System.out.println(e);
}
catch(IndexOutOfBoundsException e)
{
System.out.println("closing fileinputstream..");
}
finally
{
if (fis != null)
{
fis.close();
}
else
{
System.out.println("fileinputstream not open");
}
}
}
}