码迷,mamicode.com
首页 > 编程语言 > 详细

java实现cmd的copy功能

时间:2014-08-19 10:47:54      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:style   color   java   os   io   ar   amp   new   

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Copy {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Args not right!!!");
            System.out.println("Should by source distintion!");
            System.exit(1);
        }
        File f1 = new File(args[0]);
        File f2 = new File(args[1]);
        if (!f1.exists()) {
            System.out.println("Source file not exxit!");
            System.exit(1);
        }
        InputStream input = null;
        try {
            input = new FileInputStream(f1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        OutputStream output = null;
        try {
            output = new FileOutputStream(f2);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        if (input != null && output != null) {
            int temp = 0;   //字节流
            try {
                while ((temp = input.read()) != -1) {
                    output.write(temp);
                }
                System.out.println("Copy complete!");
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("Copy failed!");
            }
            try {
                input.close();
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

java实现cmd的copy功能,布布扣,bubuko.com

java实现cmd的copy功能

标签:style   color   java   os   io   ar   amp   new   

原文地址:http://www.cnblogs.com/vonk/p/3921402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!