Hello. I have problem with this copyFile function.
I want to copy file “nophoto.jpg” from resources to documents as “copy.jpg”.
On Corona Simulator on PC it works but on my phone it doesn’t work fine. It copies black screen with 0B, blank jpg.
copyFile
local function copyFile(dstName)
local results = false
local rfilePath = system.pathForFile( "nophoto.jpg" )
local wfilePath = system.pathForFile( dstName, system.DocumentsDirectory )
local rfh = io.open( rfilePath, "rb" )
local wfh = io.open( wfilePath, "wb" )
if not wfh then
print( "writeFileName open error!" )
return false -- error
else
-- Read the file from the Resource directory and write it to the destination directory
local data = rfh:read( "*a" )
if not data then
print( "read error!" )
return false -- error
else
if not wfh:write( data ) then
print( "write error!" )
return false -- error
end
end
end
results = 2 -- file copied
-- Clean up our file handles
rfh:close()
wfh:close()
return results
end
I use it this way: copyFile("copy.jpg")
Any thoughts?