system.ApplicationSupportDirectory

类型 常量
system.*
修订 发行版 2024.3703
关键字 系统目录、ApplicationSupportDirectory
参见 system.pathForFile()
system.CachesDirectory
system.DocumentsDirectory
system.ResourceDirectory
system.TemporaryDirectory

概览

system.pathForFile() 搭配使用,为存储和检索那些需要在应用程序会话之间保留但对用户不可见的文件创建路径。例如,这可能用于存储游戏的可下载关卡。

此属性还可以与其他 API 搭配使用,这些 API 将 baseDir 请求为参数,例如 display.newImageRect()display.save() 等。

备注
  • 在 Corona 模拟器中,这将位于每个应用程序基础上的沙盒文件夹中。你可以通过以下方式查看其目录/文件文件显示项目沙盒.

  • 在 iOS 上,此信息通过同步进行备份。

语法

system.ApplicationSupportDirectory

示例

-- Get path for file "data.txt" in the application support directory
local path = system.pathForFile( "data.txt", system.ApplicationSupportDirectory )

-- 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 )