In the Corona Simulator and on iPhone, the following code prints the contents if the remote file perfectly.
However, on Android, only garble is printed, and the file length is said to be about half of the actual length.
What is wrong?
[lua]function io.load(name)
local path = system.pathForFile(name, system.DocumentsDirectory)
local file = io.open(path, “r”)
if file then
local data = file:read("*a")
io.close(file)
return data
end
end
function main()
local file = “index.html”
local function listener(event)
for key, value in pairs(event) do
print(key, value)
end
local load = io.load(file)
print(“length”, string.len(load))
local buffer = “”
for i=1, string.len(load) do
local char = string.sub(load, i, i)
buffer = buffer … char
if char == “\n” or string.len(buffer) >= 80 then
print(buffer)
buffer = “”
end
end
end
local url = “http://www.example.com/”
network.download(url, “GET”, listener, file, system.DocumentsDirectory)
end
main()[/lua]
[import]uid: 73434 topic_id: 35581 reply_id: 335581[/import]