- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
-
- import java.io.File;
- //实现复制功能
- public class copy {
- public static void main(String args[]) throws Exception{
- if(args.length!=2){
- System.out.println("路径不正确,文件无法复制!") ;
- System.exit(0) ;
- }
- if(args[0].equals(args[1])){
- System.out.println("文件路径不相同,无法复制!") ;
- System.exit(0) ;
- }
- File f1 = new File(args[0]) ;//找到第一个文件的路径
- if(f1.exists()){ //判断路径是否正确
- File f2 = new File(args[1]) ; //找到第二个路径
- InputStream input = new FileInputStream(f1) ; //输入流
- OutputStream output = new FileOutputStream(f2) ; //输出流
- int temp = 0 ;
- while((temp = input.read())!=-1){
- output.write(temp) ;
- }
- System.out.println("文件复制成功!") ;
- input.close() ; //关闭输入流
- output.close() ; //关闭输出流
- }
- else{
- System.out.println("原路径错误!") ;
- }
- }
- }
- /*运行需要路径*/
复制代码
|