背景:使用matlab写了一个double类型的文件,想用java读出来,结果读出来的结果不一样
代码
matlab
a=[1e-1 1e-1];
fileName = "a.mat";
fileID = fopen(fileName,'w');
fwrite(fileID,a,'double');
fclose(fileID);
nfileID = fopen(fileName,'r');
tmp = fread(nfileID,'double');
fclose(nfileID);
文件十六进制显示:
java
public static void main(String[] args) throws IOException {
DataOutputStream dos = new DataOutputStream(new FileOutputStream("b.mat"));
dos.writeDouble(1e-1);
dos.writeDouble(1e-1);
dos.close();
}
文件十六进制显示:
结论
上面文件的每一排代表一个double,占8字节
可以看到,上面每一排的内容顺序都是相反的。
这和matlab和java的高低位存储有关系