Java中随机存取文件的读写顺序

Java中随机存取文件的读写顺序,java,randomaccessfile,Java,Randomaccessfile,我认为它使用randomAccessFile编写的顺序与它读取的顺序不匹配。我如何纠正这个问题?这和大/小Endian有关吗 RandomAccessFile accessor = new RandomAccessFile (new File("passwd_file"), "rws"); accessor.write(macbytes); //System.out.println(macbytes); byte[] test=new byte[(int) accessor.length(

我认为它使用randomAccessFile编写的顺序与它读取的顺序不匹配。我如何纠正这个问题?这和大/小Endian有关吗

RandomAccessFile accessor = new RandomAccessFile (new File("passwd_file"), "rws");   
accessor.write(macbytes);
//System.out.println(macbytes);
byte[] test=new byte[(int) accessor.length()];
accessor.seek(0);
accessor.read(test);

//System.out.println(test);
if (test.equals(macbytes))System.out.println("true");
else System.out.println("false");

你的测试无效。
byte[]
类不重写
Object.equals()
。尝试使用数组.equals()

您的测试无效。
byte[]
类不重写
Object.equals()
。尝试使用
Arrays.equals()

非常感谢。我已经检查了好几个小时了,一直认为这与班级类型有关,从来没有想过这与平等有关。。。对不起,我想我没有经验。非常感谢你。我已经检查了好几个小时了,一直认为这与班级类型有关,从来没有想过这与平等有关。。。对不起,我想我没有经验。。