第十五周课堂实践

实验内容

编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能

实验要求

提交测试代码和运行结果截图,加上学号水印,提交码云代码链接。

代码链接

package ketang;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by hp on 2017/5/31.
 */
public class MyOD {
    public static String format(byte []bt){
        int line=0 ;
        StringBuilder buf=new StringBuilder() ;
        for(byte d:bt){
            if(line%16==0)
                buf.append(String.format("%05x: ", line)) ;
            buf.append(String.format("%02x  ", d)) ;
            line++ ;
            if(line%16==0)
                buf.append("
");
        }
        buf.append("
") ;
        return buf.toString();
    }
    public static byte[] readFile(String file) throws IOException{
        InputStream is=new FileInputStream(file) ;
        int length=is.available() ;
        byte bt[]=new byte[length] ;
        is.read(bt) ;
        return bt;
    }
    public static  void main(String[]agrs) throws IOException{
        byte []bt=MyOD.readFile("F:\abc.txt");
        String hexData=MyOD.format(bt) ;
        System.out.println(hexData);
    }
}

运行截图

没能成功提交的原因

本次实验其实在码云上已经早早地提交上去了,刚打好了水印,准备提交找不到截图就已经结束了。

原文地址:https://www.cnblogs.com/pingcpingcuo/p/6929856.html