3

I'm a complete newbie in Lua and i've stumbled upon a problem i don't understand.

So what i'm trying to do is open a file, read the data and save it into a different file with a different name.

Here is the code

local infile = io.open(folder..'/'..f, "r")
local instr = infile:read("*all")
infile:close()

local outfile = io.open(folder..'/'..newName, "w")
outfile:write(instr)
outfile:close()

The result i get is a Source file 288Kb and a Dest file 2Kb

So again, as i'm a newbie in Lua, the fact that the problem is in infile:read is a wild guess for me, but the way i see it, it's either infile:read or outfile:write.

UPD: The content is absolutely arbitrary, which implies special symbols occur.

Thank you in advance,

Regards!

1 Answer 1

1

I've made it work by opening the in- and output file in binary mode by adding flag b in the io.open call., so the code I have now is

        local infile = io.open(folder..'/'..f, "rb")
        local instr = infile:read("*all")
        Log(instr)
        infile:close()

        local outfile = io.open(folder..'/'..newName, "wb")
        outfile:write(instr)
        outfile:close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.