when i try the under function in win,it worked.But failed when i build for android devices.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | function copyFile( srcName, srcPath, dstName, dstPath ) local results = true -- assume no errors -- Copy the source file to the destination file -- local rfilePath = system.pathForFile( srcName, srcPath ) local wfilePath = system.pathForFile( dstName, dstPath ) local rfh = io.open( rfilePath, "rb" ) local wfh = io.open( wfilePath, "wb" ) if not wfh then print( "writeFileName open error!" ) results = 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!" ) results = false -- error else if not wfh:write( data ) then print( "write error!" ) results = false -- error end end end -- Clean up our file handles rfh:close() wfh:close() return results end |
You might have not added the correct Android permissions. Trying adding the WRITE_EXTERNAL_STORAGE
permission. It is either that or your code may be incorrect. Good luck and I hope this helps.
Regards,
Jordan Schuetz
Ninja Pig Studios