Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function app.saveFile(strFilename, strValue, dir)
- local path = system.pathForFile(strFilename, dir or system.DocumentsDirectory)
- local file = io.open(path, 'w+')
- if file then
- file:write(strValue)
- io.close(file)
- end
- end
- function app.readFile(strFilename, dir)
- local theFile = strFilename
- local path = system.pathForFile( theFile, dir or system.DocumentsDirectory )
- -- io.open opens a file at path. returns nil if no file found
- local file = io.open( path, 'r')
- if file then
- -- read all contents of file into a string
- local contents = file:read('*a')
- io.close( file )
- return contents
- else
- return ''
- end
- end
- function app.readJsonFile(strFilename, dir)
- return json.decode(app.readFile(strFilename, dir))
- end
- function app.saveJsonFile(strFilename, strValue, dir)
- app.saveFile(strFilename, json.encode(strValue), dir)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement