当前位置: 代码迷 >> Java相关 >> 文件输入问题
  详细解决方案

文件输入问题

热度:322   发布时间:2007-05-22 09:04:50.0
文件输入问题

/**
* @(#)Demo.java
*
*
* @author
* @version 1.00 2007/5/22
*/

import java.io.*;
public class Demo
{

public Demo()
{

}

public static void main(String[] args)
{
try{
int acount;
byte[] bInput=new byte[100];
String str=new String();
FileInputStream file=new FileInputStream(new File("1.doc");
acount=file.read(bInput);
str=str+new String(bInput);
System.out.print(str);
}catch(IOException e)
{
System.out.println(e.getMessage());
}catch(FileNotFoundException er)
{
System.out.println(er.getMessage());
}

}
}
我觉得这段代码没有问题啊!

--------------------Configuration: <Default>--------------------
E:\学习\Java\Demo.java:31: 已捕捉到异常 java.io.FileNotFoundException
}catch(FileNotFoundException er)
^
1 错误

Process completed.

[此贴子已经被作者于2007-5-22 9:08:15编辑过]

搜索更多相关的解决方案: 文件  输入  

----------------解决方案--------------------------------------------------------
FileNotFoundException是IOException的子类,所以应该把它放到前面,而不是放在后面

也就是说,应该先捕获FileNotFoundException,再捕获IOException,

----------------解决方案--------------------------------------------------------
o .这样子啊!谢谢了!
----------------解决方案--------------------------------------------------------
  相关解决方案