Sqlite3 数据库文件无法在 Android 设备上运行[Corona SDK]

我试图将数据库文件复制到system.documentsDirectory中,以便能够在设备上写入数据库文件,如此处所述:http://docs.coronalabs.com/api/library/system/pathForFile.html

但是,在设备上似乎没有起作用。您能解析代码并告诉我我错在哪里吗?

–DAO模块中

local sqlite3 = require "sqlite3"

Dao={}

path = system.pathForFile( "barfi" , system.DocumentsDirectory )

db = sqlite3.open(path)

–项目文件夹中(保存为)

barfi.txt

–主函数中

local function copyFile( srcName, srcPath, dstName, dstPath, overwrite )
    local results = true – 默认无错误

    –将源文件复制到目标文件
    –
    local rfilePath = system.pathForFile( srcName, srcPath )
    local wfilePath = system.pathForFile( dstName, dstPath )

    local rfh = io.open( rfilePath, "rb" )
    local wfh = io.open( wfilePath, "wb" )

    if  not wfh then
        print( "writeFileName open error!" )
        results = false –错误
    else
        –从资源目录读取文件并将其写入目标目录
        local data = rfh:read( "*a" )

        if not data then
            print( "read error!" )
            results = false –错误
        else
            if not wfh:write( data ) then
                print( "write error!" )
                results = false –错误
            end
        end
    end

        –清除文件句柄
        rfh:close()
        wfh:close()

        return results
end

copyFile( "Barfi.txt", nil, "Barfi", system.DocumentsDirectory, true )
点赞
用户1463542
用户1463542

这个代码正在工作良好。数据库在设备上也正在工作。必须是其他问题。

2014-03-15 13:19:11