java MyCP -xt XXX1.bin XXX2.txt 用來二進制文件把轉化爲文本文件(內容爲十進制數字)java
提交測試代碼和運行結果截圖,加上學號水印,提交碼雲代碼連接。git
須要提交博客和答辯app
import java.io.*; public class MyCP{ public static void main(String[] args) throws IOException { //輸入十進制文本 String filepath = "G:/學習的zxy最美麗/java/zxyjava/lll/from.txt"; String s =dataInputStream(filepath); //將獲得的二進制數存成文本 FileOutputStream fps = new FileOutputStream("G:/學習的zxy最美麗/java/zxyjava/lll/to.txt"); fps.write(s.getBytes()); fps.close(); } public static String dataInputStream(String filepath) throws IOException { File file = new File(filepath); DataInputStream dps = new DataInputStream(new FileInputStream(file)); StringBuilder byData = new StringBuilder(); byte bt = 0; for(int i=0;i<file.length();i++) {//返回一個字符串二進制的無符號整數 bt = dps.readByte();//按照字節讀取 String str = Integer.toBinaryString(bt); if(str.length() == 1) { str = "0"+str; } byData.append(str.toUpperCase()); } return byData.toString(); } }