Type Function Object File Library io.* Return value none Revision Release 2021.3646 Keywords write, files See also io.open() Reading and Writing Files
For security reasons, you are not allowed to write files in the
system.ResourceDirectory (the directory where the application is stored). You must specify either
system.CachesDirectory in the system.pathForFile() function when opening the file for writing.
File:write( arg1 [, arg2] [, ...] )
String. One or more strings to be written to the file represented by the
-- Data (string) to write local saveData = "My app state data" -- Path for the file to write local path = system.pathForFile( "myfile.txt", system.DocumentsDirectory ) -- Open the file handle local file, errorString = io.open( path, "w" ) if not file then -- Error occurred; output the cause print( "File error: " .. errorString ) else -- Write data to file file:write( saveData ) -- Close the file handle io.close( file ) end file = nil