Yes, read my code, see how it works, see it working, experiment, learn.
if( io.readFile ) then print("ERROR! io.readFile() exists already") else function io.readFile( fileName, base ) local base = base or system.DocumentsDirectory local fileContents if( io.exists( fileName, base ) == false ) then return nil end local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end local f=io.open(fileName,"r") if (f == nil) then return nil end fileContents = f:read( "\*a" ) io.close(f) return fileContents end end if( io.writeFile ) then print("ERROR! io.writeFile() exists already") else function io.writeFile( dataToWrite, fileName, base ) local base = base or system.DocumentsDirectory local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end local f=io.open(fileName,"w") if (f == nil) then return nil end f:write( dataToWrite ) io.close(f) end end
Sorry, but I gave you an alternate solution above and you rejected it as, “I tried that and it didn’t work…”. So, the only alternative is for me to show you a working example which I’ve done.
Unfortunately, I don’t have the time right now to take your code, run in locally, debug it, and give it back to you fixed, which I guess is the third option… :unsure: