Hello all.
I’ve used LFS to create a custom directory named “Palettes” in my system.DocumentsDirectory, but I can’t figure out how to save data to that folder.
I see the “pathToFile” API, but I’m not sure how to apply it in this case.
I’m retrieving JSON data from a webservice and it’s getting the data fine, just not sure how to steer it into that directory.
Here’s my JSON code from a previous example from way back:
[lua]
– jsonFile() loads json file & returns contents as a string
local jsonFile = function( filename, base )
print("base "…base)
– set default base dir if none specified
if not base then base = system.DocumentsDirectory end
– create a file path for corona i/o
local path = system.pathForFile( filename, base )
– will hold contents of file
local contents
– 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
contents = file:read( “*a” )
io.close( file ) – close the file after using it
end
return contents
end
[/lua]
The line with
if not base then base = system.DocumentsDirectory end
is where I think I could use a pointer!
Appreciate any help.
-Mario
PS How do I format the code as LUA? The code widget only showed a couple of languages or ‘autodetect’??