FileCopy

 

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class Copy {
     String order;
     String url1;
     String url2;
 public Copy(String order, String url1, String url2) {
  super();
  this.order = order;
  this.url1 = url1;
  this.url2 = url2;
 }
 public void did  () {
  byte b[]=null;
  int len = 0;
  File file1 = new File(this.url1);
  
  if(file1.exists()){

  try {
   InputStream input = new FileInputStream(file1);     
   b= new byte[(int)file1.length()];
          len = input.read(b);
  } catch (Exception e){  
   e.printStackTrace();
  }
  }
  else {
   System.out.println("系统找不到你要拷贝的文件");
  }
  File file2 = new File(this.url2);
  try {
   OutputStream  OutputStream1 = new FileOutputStream(file2); 
   OutputStream1.write(b, 0, len);
  } catch (Exception e) {  
   e.printStackTrace();
  }
  
  System.out.println("拷贝文件成功"); 
 } 

 public static void main(String[] args){
  if(args.length != 3){
   System.out.println("输入参数个数出错");
   System.exit(0);
  } else if(!(args[0].toString().equalsIgnoreCase("copy"))){
   System.out.println("输入第一个参数出错"); 
   System.exit(0);
  }else {
   Copy copy = new Copy(args[0], args[1], args[2]);
         copy.did();
  }  
 }

}

你可能感兴趣的:(FileCopy)