类型 常量 库 system.* 版本 2024.3703 版 关键词 系统目录、临时目录 另请参见 system.pathForFile() system.ApplicationSupportDirectory system.CachesDirectory system.DocumentsDirectory system.ResourceDirectory
配合 system.pathForFile() 使用创建路经,用于存储和检索仅需在应用程序运行期间保留的文件。路经为 /tmp
。
此属性还可以配合将 baseDir
作为参数的其他 API 使用,例如 display.newImageRect()。
在 Corona Simulator 中,此属性将位于一个
system.TemporaryDirectory
-- Get path for file "data.txt" in the temporary directory local path = system.pathForFile( "data.txt", system.TemporaryDirectory ) -- Open the file from the path local fh, reason = io.open( path, "r" ) if fh then -- File exists; read its contents into a string local contents = fh:read( "*a" ) print( "Contents of " .. path .. "\n" .. contents ) else -- File open failed; output the reason print( "File open failed: " .. reason ) -- Create file since it doesn't exist yet fh = io.open( path, "w" ) if fh then print( "Created file" ) else print( "Create file failed!" ) end local numbers = { 1,2,3,4,5,6,7,8,9 } fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" ) for _,v in ipairs( numbers ) do fh:write( v, " " ) end fh:write( "\nNo more data\n" ) end io.close( fh )