zoukankan      html  css  js  c++  java
  • java实现cmd的copy功能

    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();
                }
            }
        }
    }

  • 相关阅读:
    Python之坐标轴刻度细化、坐标轴设置、标题图例添加
    探索性数据分析
    http://blog.csdn.net/milton2017/article/details/54406482
    libsvm学习日记--1
    推荐系统评测指标—准确率(Precision)、召回率(Recall)、F值(F-Measure)
    python中if __name__ == '__main__': 的解析
    Python类
    TweenMax学习一
    vuejsLearn---通过手脚架快速搭建一个vuejs项目
    vuejsLearn--- -- 怎么查看、修改、追加数据---->data对象
  • 原文地址:https://www.cnblogs.com/vonk/p/3921402.html
Copyright © 2011-2022 走看看