La descarga está en progreso. Por favor, espere

La descarga está en progreso. Por favor, espere

CAPÍTULO 10 Trabajar con Ficheros.

Presentaciones similares


Presentación del tema: "CAPÍTULO 10 Trabajar con Ficheros."— Transcripción de la presentación:

1 CAPÍTULO 10 Trabajar con Ficheros

2 Contenidos 1 2 3 4

3 Escritura secuencial de bytes
texto.txt FS buffer Flujo de Salida hacia Fichero H O L A H O L A matriz de bytes FileOutputStream FS; Byte[ ] buffer = new byte[7]; Fichero FS = new FileOutputStream(“texto.txt”, true); FS = new FileOutputStream(“texto.txt”); Rellenar matriz FS.write(buffer, 0, 3); Ejercicio Página 234

4 Lectura secuencial de bytes
texto.txt FE buffer Flujo de Entrada desde Fichero H O L A H O L A H O L A matriz de bytes FileInputStream FE; Byte[ ] buffer = new byte[7]; Fichero FE = new FileInputStream(“texto.txt”); FE.read(buffer, 0, 3); Ejercicio Página 236

5 CLASE FILE C: F Hola Mundo …println( F.getName() ) texto.txt
…println( F.getParent() ) documentos …println( F.getPath() ) proyecto documentos\texto.txt …println( F.getAbsolutePath() ) documentos C:\proyecto\documentos\texto.txt …println( F.length() ) 10 texto.txt F …println( F.exists() ) Hola Mundo true / false …println( F.isFile() ) true …println( F.isDirectory() ) false File F2 = new File(“…texto2.txt“) F.renameTo(F2) Cambia el nombre del fichero F.delete() File F = new File(“documentos\\texto.txt”); Elimina el fichero

6 Crea el directorio si no existe File F = new File(“documentos”);
CLASE FILE C: F.list() proyecto m[0] reclamación.doc foto.jpg música.mp3 matriz m m[1] documentos m[...] m[n] reclamación.doc foto.jpg música.mp3 F F.mkdir() Crea el directorio si no existe F.mkdirs() Crea los directorios que sean necesarios File F = new File(“documentos”);

7 CLASE FILE C: F Hola Mundo F = new File(“documentos\\texto.txt”); FE
proyecto documentos F = new File(“documentos\\texto.txt”); F texto.txt FE = new FileInputStream(“documentos\\texto.txt”); Hola Mundo Flujo de Entrada FE buffer FE = new FileInputStream(F); FE.read(buffer, 0, 10);

8 Escritura secuencial de datos primitivos
texto.txt String nombre Antonio long teléfono boolean casado False Data Output Stream (Flujo de Salida de Datos) DOS File Output Stream (Flujo de Salida hacia Fichero) FOS Antonio True bytes[] buffer Luis False Fichero DataOutputStream DOS; DOS = new DataOutputStream(FOS); FOS = new FileOutputStream(“texto.txt”); FileOutputStream FOS; DOS.writeUTF(nombre); DOS.writeLong(teléfono); DOS.writeBoolean(casado); FOS.write(buffer, 0, 3); Ejemplo en Página 241

9 Lectura secuencial de datos primitivos
texto.txt String nombre long teléfono boolean casado Data InputStream (Flujo de Entrada de Datos) DIS File Input Stream (Flujo de Entrada desde Fichero) FIS Antonio True Luis False Antonio Hola Mundo Byte[] buffer Fichero True DataInputStream DIS; DIS = new DataInputStream(FIS); FIS = new FileInputStream(“texto.txt”); FileInputStream FIS; DIS.readUTF(nombre); FIS.read(buffer, 0, 10); DIS.readLong(teléfono); DIS.readBoolean(casado); Ejemplo en Página 242

10 Acceso Aleatorio a Ficheros
nombre = Agenda.readUTF() ANTONIO teléfono = Agenda.readLong() telefonos.bd Agenda.seek(38) RandomAccessFile (Fichero de Acceso Aleatorio) Agenda Antonio Pedro nombre = Agenda.readUTF() JOSE teléfono = Agenda.readLong() Agenda.seek(0) Agenda.writeUTF(“IGNACIO “) Fichero Agenda.writeLong( ) RandomAccessFile Agenda; Agenda = new RandomAccessFile(“telefonos.bd”, “rw”); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 A N T O I 9 5 6 3 4 8 7 P E D R 1 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 3 4 7 6 5 J O S E 8 1 R G I


Descargar ppt "CAPÍTULO 10 Trabajar con Ficheros."

Presentaciones similares


Anuncios Google