为了分析mcu文件head信息,需要将mcu文件转化成二进制byte流,并且能看到每一位对应16进制数是多少,实现方法如下:
import java.io.UnsupportedEncodingException;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
class JavaTest{
public static void main(String[] args) throws UnsupportedEncodingException {
try{
FileInputStream fint = new FileInputStream("D:/Q1014HL-A04CA1-0929.mcu");
FileOutputStream fout = new FileOutputStream("D:/Q1014HL-A04CA1-0929.txt");
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while (-1 != (len = fint.read(buffer))) {
outStream.write(buffer, 0, len);
}
byte[] byteOut = outStream.toByteArray();
StringBuilder sb = new StringBuilder();
if (byteOut != null) {
for (int i = 0; i < byteOut.length; ++i)
sb.append(String.format("%02x ", byteOut[i]));
}
fout.write(sb.toString().getBytes());
outStream.close();
fint.close();
fout.close();
}catch (Exception e){e.printStackTrace();}
}
}