- import java.io.*;
- class Test8
- {
- public static void main(String[] args) throws IOException
- {
- //输出当前时间 毫秒
- System.out.println(System.currentTimeMillis());
- //建立输入输出流 对象
- BufferedInputStream bufis =new BufferedInputStream(new FileInputStream("d:\\ding.rar"));
- BufferedOutputStream bufos =new BufferedOutputStream(new FileOutputStream("d:\\dingcopy.rar"));
- //建立数组 用于存储缓冲数据
- byte [] buf = new byte[1024*4];
-
- //检测异常
- try
- {
- //读取 输入流 每次1024个字节
- while (bufis.read(buf,1024,1024)!=-1)
- {
- //输出到文件 每次1024个字节
- bufos.write(buf,1024,1024);
- }
- }
- //出现异常执行代码块
- catch (IOException e)
- {
- System.out.println(e.getMessage());
- }
- //必须执行代码块
- finally
- {
- //关闭输入流 与输出流
- bufos.close();
- bufis.close();
- //输出当前时间 毫秒
- System.out.println(System.currentTimeMillis());
- }
- }
- }
复制代码 |
|