Está en la página 1de 7

BYTES

Ing. Msc. Euclides Panduro Padilla


CONCEPTOS
▪ Programs use byte streams
to perform input and output
of 8-bit bytes. All byte
stream classes are
descended from
InputStream and
OutputStream.
▪ There are many byte stream
classes. We'll focus on the
file I/O byte streams,
FileInputStream and
FileOutputStream.

Ing. Msc. Euclides Panduro Padilla 2


CONCEPTOS
▪ Manejar no solo archivos de texto, sino cualquier tipo de archivo, para su envió o recepcion (pdf,
video,texto, etc), serán convertidos a bytes

FICHERO

Stream bytes: Enteros [0,255]

Ing. Msc. Euclides Panduro Padilla 3


CONCEPTOS

▪ Clases:
▪ FileInputStream
▪ Read()

FileOutputStream
Write()

Ing. Msc. Euclides Panduro Padilla 4


LEER A UN ARCHIVO - FileInputstream

FileInputStream archivo = new FileInputStream(file);


while(!end_file){
in_byte = archivo.read();
if (in_byte == -1)
end_file = true;
}

Ing. Msc. Euclides Panduro Padilla 5


ESCRIBIR A UN ARCHIVO - FileOutputstream
▪ Mover un archivo de un lugar a otro, pasos:
▪ 1. Leer los bytes.
▪ 2. Almacenar los bytes
▪ 3. Crear un archivo nuevo con los bytes almacenados

FileOutputStream archivo_nuevo = new FileOutputStream(ruta);


for (int i = 0; i< total_bytes.length;i++){
archivo_nuevo.write(total_bytes[i]);
}

Ing. Msc. Euclides Panduro Padilla 6


VEAMOS EL EJEMPLO

Ing. Msc. Euclides Panduro Padilla 7

También podría gustarte