I am trying to copy files using BufferedInputStream, and this error occurred when compile:
BufferedByteStreamCopy2.java:22: error: unreported exception IOException; must be caught or declared to be thrown bin.close(); ^ BufferedByteStreamCopy2.java:24: error: unreported exception IOException; must be caught or declared to be thrown bout.close(); ^
Could you help me to explain this? How can I modify the code? Many thanks!
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();
}
} }