【发布时间】:2014-03-29 07:53:36
【问题描述】:
我正在尝试使用BufferedInputStream复制文件,编译时出现此错误:
BufferedByteStreamCopy2.java:22:错误:未报告的异常IOException;必须被抓住或宣布被扔掉 bin.close(); ^ BufferedByteStreamCopy2.java:24:错误:未报告的异常 IOException;必须被抓住或宣布被扔掉 回合.close(); ^
你能帮我解释一下吗?如何修改代码?非常感谢!
import java.io.*;
public class BufferedByteStreamCopy2 {
public static void main(String[] args) {
BufferedInputStream bin = null;
BufferedOutputStream bout = null;
try {
FileInputStream fin = new FileInputStream(args[0]);
bin = new BufferedInputStream(fin);
FileOutputStream fout = new FileOutputStream(args[1]);
bout = new BufferedOutputStream(fout);
int c;
while ((c = bin.read()) != -1)
bout.write(c);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Not enough parameter.");
} catch (FileNotFoundException e) {
System.out.println("Could not open the file:" + args[0]);
} catch (Exception e) {
System.out.println("ERROR copying file");
} finally {
if (bin != null)
bin.close();
if (bout != null)
bout.close();
}
} }
【问题讨论】:
-
您提供的代码编译得很好。鉴于您的公共类的名称和错误中报告的文件名,您确定这不仅仅是拥有两份源代码副本的问题 - 一份工作,一份损坏?