本帖最后由 老貓钓鱼 于 2014-3-8 21:41 编辑
用字节流来复制
- package com.item.io;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class RarCopyDemo {
- /**
- * @param args
- *
- */
- public static void main(String[] args) {
-
- BufferedInputStream bis = null;
- BufferedOutputStream bos = null;
-
- try{
- bis = new BufferedInputStream(new FileInputStream("c:\\1.rar"));
- bos = new BufferedOutputStream(new FileOutputStream("c:\\2.rar"));
- byte[] buff = new byte[1024];
- int len = 0;
- while((len=bis.read(buff)) != -1 ) {
- bos.write(buff, 0, len);
- }
- }catch(IOException e) {
-
- }finally {
- if(bis != null) {
- try {
- bis.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- throw new RuntimeException("关闭失败");
- }
-
- }
- if(bos != null) {
- try {
- bos.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- throw new RuntimeException("关闭失败");
- }
- }
- }
- }
- }
复制代码
|