FileReader
es un objeto que permite leer un fichero.
abort()
). (Function)El objeto FileReader
permite leer ficheros del sistema de archivos del dispositivo. Los ficheros pueden ser leídos como texto plano o codificados en base64. Los desarrolladores pueden registrar sus propias funciones a los eventos ‘loadstart’, ‘progress’, ‘load’, ‘loadend’, ‘error’ y ‘abort’.
Argumentos:
File
a leer.function win(file) { var reader = new FileReader(); reader.onloadend = function(evt) { console.log("read success"); console.log(evt.target.result); }; reader.readAsDataURL(file); }; var fail = function(evt) { console.log(error.code); }; entry.file(win, fail);
Argumentos:
File
a leerfunction win(file) { var reader = new FileReader(); reader.onloadend = function(evt) { console.log("read success"); console.log(evt.target.result); }; reader.readAsText(file); }; var fail = function(evt) { console.log(error.code); }; entry.file(win, fail);
function win(file) { var reader = new FileReader(); reader.onloadend = function(evt) { console.log("read success"); console.log(evt.target.result); }; reader.readAsText(file); reader.abort(); }; function fail(error) { console.log(error.code); } entry.file(win, fail);
<!DOCTYPE html> <html> <head> <title>Ejemplo de FileReader</title> <script type="text/javascript" charset="utf-8" src="phonegap.js"></script> <script type="text/javascript" charset="utf-8"> // Espera a que phonegap se inicie // function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); } // PhoneGap esta listo // function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); } function gotFS(fileSystem) { fileSystem.root.getFile("readme.txt", {create: true}, 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); } </script> </head> <body> <h1>Ejemplo</h1> <p>Lectura de ficheros</p> </body> </html>