Tôi đang cố gắng làm việc với các tệp trên iOS, sử dụng Phonegap [cordova 1.7.0]. Tôi đọc cách truy cập các tập tin và đọc chúng trên API Documentation khoảng cách điện thoại. Nhưng tôi không biết, khi tập tin được đọc, nơi nó sẽ được viết? & Làm cách nào để xuất văn bản, hình ảnh hoặc bất kỳ văn bản nào có chứa trên màn hình iPhone?Truy cập các tập tin bằng cách sử dụng Phonegap
Dưới đây là đoạn code tôi đang sử dụng:
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);
}
ở đâu để tôi xác định tập tin tôi muốn đọc? – donkey
+1 Tôi chỉ định tệp ở đâu? –
@john_cat & oasisweng: Tôi đã thêm nhận xét với ví dụ mà tôi nghĩ là giải quyết câu hỏi của bạn. HTH! – sherb