MyOD
内容
编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能
import java.io.*;
import java.util.Scanner;
/**
*Created by xinag on 2018/6/10.
*/
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("
00020: ");
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;
Scanner scanner = new Scanner(System.in);
String adress = null;
try {
System.out.println("Input your file adress:");
adress = scanner.next();
fis = new FileInputStream(adress);
dump(fis);
}catch(Exception e) {
System.out.println(e);
}
}
}