編寫MyCP.java 實現相似Linux下cp XXX1 XXX2的功能,要求MyCP支持兩個參數:java
提交測試代碼和運行結果截圖,加上學號水印,提交碼雲代碼連接。git
須要提交博客和答辯app
import java.io.*; public class MyCP { public static void main(String[] args) throws Exception{ String y1, y2, c, result = "", num; c = args[0]; y1 = args[1]; y2 = args[2]; try { FileInputStream fis = new FileInputStream(y1); InputStreamReader isr = new InputStreamReader(fis); BufferedReader in = new BufferedReader(isr); PrintStream ps = new PrintStream(y2); num = in.readLine(); if (c.equals("-xt")) { result = Integer.valueOf(num, 2).toString(); } else if (c.equals("-tx")) { int n, temp = Integer.parseInt(num); for (int i = temp; i > 0; i = i / 2) { if (i % 2 == 0) { n = 0; } else { n = 1; } result = n + result; } } else { System.out.println("Error!"); } ps.append(result); ps.flush(); ps.close(); } catch (IOException e) { System.out.println(e); } } }
!碼雲連接測試