- package com.vince.io;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- public class TestCopy {
- /**
- * @param args
- */
- public static void main(String[] args) {
- String newFile="D:\\java.rmvb";
- String oldFile="E:\\java.rmvb";
- Copy(newFile,oldFile);
- }
- public static void Copy(String newFile,String oldFile){
- try {
- File of=new File(oldFile);
- int len=0;
- if(of.exists()){
- InputStream fis=new FileInputStream(oldFile);;
- FileOutputStream fos=new FileOutputStream(newFile);
- byte[] buffer=new byte[10240]; //[color=Red]这里改变长度[/color]
- while((len=fis.read(buffer))!=-1){
- fos.write(buffer, 0, len);
- }
- System.out.println("success");
- fis.close();
- fos.close();
- }
- } catch (Exception e) {
- System.out.println("错误");
- e.printStackTrace();
- }
- }
- }
复制代码 |