我知道這是舊的,但與鏈路上的代碼中的實際問題(除了已經由布賴恩·伯頓博士提到)是他們不關閉最初打開的文件的情況下,不爲空。因此,而不是:
if(file == nil)then
-- Doesn't Already Exist, So Copy it In From Resource Directory
pathSource = system.pathForFile(dbName, system.ResourceDirectory)
fileSource = io.open(pathSource, "r")
contentsSource = fileSource:read("*a")
-- Write Destination File in Documents Directory
pathDest = system.pathForFile(dbName, system.DocumentsDirectory)
fileDest = io.open(pathDest, "w")
fileDest:write(contentsSource)
-- Done
io.close(fileSource)
io.close(fileDest)
end
你應該在末尾添加和ELSE子句,像這樣:
if(file == nil)then
-- Doesn't Already Exist, So Copy it In From Resource Directory
pathSource = system.pathForFile(dbName, system.ResourceDirectory)
fileSource = io.open(pathSource, "rb")
contentsSource = fileSource:read("*a")
-- Write Destination File in Documents Directory
pathDest = system.pathForFile(dbName, system.DocumentsDirectory)
fileDest = io.open(pathDest, "wb")
fileDest:write(contentsSource)
-- Doneb
io.close(fileSource)
io.close(fileDest)
else
io.close(file)
end
乾杯!
下面的鏈接,並讀取響應後,我會問你是如何複製文件?你打開它在二進制模式? 該解決方案應該爲你工作。 –