- 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();
- }
- }
- }
- }
- }
复制代码 |
|