2
我深化发展映射目的的应用程序将数据写入到它.. 我创建KML和JSON字符串,我需要将它们存储在文件中的手机内存,这样做,我用了以下代码:创建一个文件,并用离子
var fileObject;
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady()
{
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,onFileSystemSuccess, fail);
}
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile("readme.txt",{create: true, exclusive: false},gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileObject = fileEntry;
$('#saveFile_btn').on('click', function() {
saveFileContent();
});
}
function saveFileContent() {
fileObject.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
var myText = document.getElementById('my_text').value;
writer.write(myText);
writer.onwriteend = function(evt) {
$('#message').html('<p>File contents have been written.<br /><strong>File path:</strong> ' + fileObject.fullPath + '</p>');
var reader = new FileReader();
reader.readAsText(fileObject);
reader.onload = function(evt) {
$('#contents').html('<strong>File contents:</strong> <br />'+ evt.target.result);
};
};
}
function fail(error){
alert(error.code);
}
结果不是错误,但我在内存中找不到该文件。