新手求问题还请大哥们帮忙!

fantasy1983 2004-04-13 03:22:03
学java 的时候有一个例外处理的程序!不懂!能不能解释一下!!谢谢!
import java.io.*;

class exceptiondemo{

public static void main(string arge[])throws IOException{

FileInputStream fis = null;

try{

system.out.println("first argument is "+args[0]);

fis = new fileinputstream("text");

system.out.println("content of text is :");

int b;

while((b=fis.read())!=-1){

system.out.priant((char)b);

}

}catch(filenotfoundexception e){

system.out.println(e);

}catch(ioexception e){

sysetm.out.println(e);

}catch(indexoutofboudsexception e){

system.out.println("closing fileinputstream..");

fis.close();

}else{

system.out.println("fileinputstream not open");

}
}
}
}


还请各位老大多多帮忙呀!
...全文
56 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantasy1983 2004-04-14
  • 打赏
  • 举报
回复
谢谢二位大哥!
新来的萌新 2004-04-13
  • 打赏
  • 举报
回复
嘿嘿! oxv(花生壳) 动作比我快哦!
新来的萌新 2004-04-13
  • 打赏
  • 举报
回复
import java.io.*;
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");
}
}
}
}
oxv 2004-04-13
  • 打赏
  • 举报
回复
上面写了注释我就不写了,稍微改了改你的程序

import java.io.*;
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");
}
}
oxv 2004-04-13
  • 打赏
  • 举报
回复
写错了很多地方啊,大小写不要混乱了
跟else配套的if好象我都没看到嘛
新来的萌新 2004-04-13
  • 打赏
  • 举报
回复
看你的名字你是不是很喜欢Jay,嘿嘿!^_^
新来的萌新 2004-04-13
  • 打赏
  • 举报
回复
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");

}
}
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧