gpt4 book ai didi

java - Java中RandomAccessFile的读写顺序

转载 作者:行者123 更新时间:2023-12-02 02:52:38 44 4
gpt4 key购买 nike

我认为它用 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");

最佳答案

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

关于java - Java中RandomAccessFile的读写顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43572154/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com