我尝试将数据库文件复制到systems.documentsDirectory,以便能够写入设备中的数据库文件,如下所述:http://docs.coronalabs.com/api/library/system/pathForFile.html
但是,它似乎无法在设备中运行。你能否分析一下代码并告诉我我做错了什么?
- IN DAO MODULE
local sqlite3 = require "sqlite3"
Dao={}
path = system.pathForFile( "barfi" , system.DocumentsDirectory )
db = sqlite3.open(path)
- IN PROJECT FOLDER(保存为)
barfi.txt
- 主要
local function copyFile( srcName, srcPath, dstName, dstPath, overwrite )
local results = true -- assume no errors
-- Copy the source file to the destination file
--
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 -- error
else
-- Read the file from the Resource directory and write it to the destination directory
local data = rfh:read( "*a" )
if not data then
print( "read error!" )
results = false -- error
else
if not wfh:write( data ) then
print( "write error!" )
results = false -- error
end
end
end
-- Clean up our file handles
rfh:close()
wfh:close()
return results
end
copyFile( "Barfi.txt", nil, "Barfi", system.DocumentsDirectory, true )
答案 0 :(得分:0)
这段代码很好用。数据库正在设备中工作。它必须是smt else。