我正在嘗試使用Phonegap [cordova 1.7.0]在iOS上使用文件。 我讀了如何訪問文件並在電話差距的API Documentation上讀取它們。但是我不知道,當文件被讀取時它會被寫入哪裏? &如何輸出文本,圖像或iPhone屏幕上包含的任何文本?使用Phonegap訪問文件
下面是我使用的代碼:
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file){
readDataUrl(file);
readAsText(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as text");
console.log(evt.target.result);
};
reader.readAsText(file);
}
function fail(evt) {
console.log(evt.target.error.code);
}
我在哪裏指定我想讀的文件? – donkey
+1我在哪裏指定文件? –
@john_cat&oasisweng:我已經添加了一個評論,並提供了一個我認爲可以解決您的問題的示例。 HTH! – sherb