我在Android 7调试电话上使用Phonegap(CLI 7),将一个简单的字符串写入持久文件。这是我的代码:
权限:
<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external,assets,root" />
源代码:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function fail(){
console.log('fail');
}
function gotFS(fileSystem) {
var path = "test.txt";
fileSystem.root.getFile(path, {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write("some sample text");
}
尽管,该应用在将数据写入文件后仍向我发送了一条成功消息,但我还是无法在我的物理智能手机的本地存储中找到该文件(test.txt)。我想打开文件检查文件内容。它藏在某个地方吗?为什么在任何地方都找不到它?还有其他建议为什么写文件可能出错了?这里的想法用光了...