我只是想从二进制文件中读/写.我一直在关注这个教程,它的工作原理......除了它似乎是在写一个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
Run Code Online (Sandbox Code Playgroud)