黑马程序员技术交流社区
标题:
这是一个异常处理的标准代码
[打印本页]
作者:
孙广浩
时间:
2015-11-14 21:35
标题:
这是一个异常处理的标准代码
package cn.itcast;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo5 {
public static void main(String[] args) {
// 创建输入流对象
BufferedInputStream bis = null;
// 创建输出流对象
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream("copy1.mp3"));
bos = new BufferedOutputStream(new FileOutputStream("copy3.mp3"));
// 读写操作
byte[] bys = new byte[1024];
int len = 0;
while ((len = bis.read(bys)) != -1) {
bos.write(bys, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
// 释放资源
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
复制代码
作者:
oup
时间:
2015-11-14 21:40
暂时看不懂,就学了一点点
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2