实验MyOD
实验MyOD
编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能
提交测试代码和运行结果截图,加上学号水印,提交码云代码链接。
代码如下:
(刚开始没有实现-tc的功能,又重新修改了)
/**
* Created by XY on 2017/5/31.
*/
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class MyOD {
public static void dump(InputStream src)
throws IOException {
try (InputStream input = src) {
byte[][] data = new byte[50][1];
byte[][] transf = new byte[50][1];
int i = 0, j = 0, num;
System.out.print("00010: ");
while (input.read(data[i]) != -1) {
num = (int) data[i][0];
System.out.printf("%5s", Integer.toHexString(num));
i++;
}
System.out.print("\n00020: ");
while (j < i) {
transf[j][0] = (byte) (data[j][0] - 0x30);
System.out.printf("%5d", transf[j][0]);
j++;
}
System.out.println();
}
}
public static void main(String[] args) {
FileInputStream fis = null;
try {
fis = new FileInputStream("C:\\Users\\XY\\Documents\\abc.txt");
dump(fis);
} catch (Exception e) {
System.out.println(e);
}
}
}
建立的abc.txt如下:
123456789abc