【问题标题】:Read and Write order of RandomAccessFile in Java [duplicate]Java中RandomAccessFile的读写顺序[重复]
【发布时间】:2017-04-23 14:06:04
【问题描述】:

我认为它用 randomAccessFile 写入的顺序与它读取的顺序不匹配。我该如何纠正?跟大/小端有关系吗?

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");

【问题讨论】:

标签: java randomaccessfile


【解决方案1】:

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

【讨论】:

  • 非常感谢。我已经检查了好几个小时了,一直认为这与类类型有关,从没想过它与 equals 有任何关系......对不起,我想我没有经验......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多