我只是想从一个二进制文件中读取/写入数据。我一直在按照这个教程进行操作,它也能正常工作……但似乎将数据写入了一个txt文件中。我在测试时给文件命名为test.bin,但记事本可以打开并正确显示它,所以我认为它实际上不是一个二进制文件。我已经使用了"wb"和"rb"来告诉它这是一个二进制文件,对吗?
if arg[1] == "write" then
local output = assert(io.open(arg[2], "wb"))
output:write(arg[3]) --3rd argument is written to the file.
assert(output:close())
elseif arg[1] == "read" then
local input = assert(io.open(arg[2], "rb"))
print(input:read(1)) --Should read one byte, not one char/int. Right?
end