public class IO流异常处理 {
public void test1() {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream("demo4.jpg"));
bos = new BufferedOutputStream(new FileOutputStream("demo44.jpg"));
int len = -1;
byte[] buf = new byte[1024];
while ((len = bis.read(buf)) != -1) {
bos.write(buf, 0, len);
bos.flush();
}
;
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (bos != null) {
bos.close();
}
} catch (IOException e) {
bos = null;
e.printStackTrace();
}
try {
if (bis == null) {
return;
}
bis.close();
} catch (Exception e2) {
bis = null;
e2.printStackTrace();
}
}
}
}
|
|