C:\Users\帅帅\Desktop
- //用缓冲区对象完成一个对Mp3文件的拷贝
- import java.io.*;
- public class CopyMp3 {
- public static void main(String[] args)
- {
- copy_1();
- }
- public static void copy_1()
- {
- FileOutputStream fos = null;
- FileInputStream fis = null;
- try
- {
- fos = new FileOutputStream("2.mp3");
- fis = new FileInputStream("1.mp3");
- BufferedOutputStream bufos = new BufferedOutputStream(fos);
- BufferedInputStream bufis = new BufferedInputStream(fis);
- int by = 0;
- while ((by =bufis.read())!=-1)
- {
- bufos.write(by);
- }
- }
- catch (IOException e )
- {
- throw new RuntimeException("读写异常");
- }
- finally
- {
- if (fos!=null)
- {
- try
- {
- fos.close();
- }
- catch (IOException e )
- {
- throw new RuntimeException("写入流关闭异常");
- }
- }
- if (fis!=null)
- {
- try
- {
- fis.close();
- }
- catch (IOException e )
- {
- throw new RuntimeException("读取流关闭异常");
- }
- }
- }
- }
- }
复制代码 |
|