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);
}
結果不是錯誤,但我在內存中找不到該文件。