Flujo de E / S de revisión de Java :
1
1) Según la dirección del flujo de datos:
flujo de entrada, flujo de salida;
2) Según la unidad de procesamiento de datos:
flujo de bytes, flujo de caracteres;
3) Según la función:
flujo de nodo, flujo de procesamiento;
2
Todos los flujos en java.io. * se heredan de las siguientes cuatro categorías;
3
Flujo nodal: leer datos directamente desde la fuente de datos;
flujo de procesamiento: sobre la base del flujo existente, a través del flujo existente El procesamiento proporciona programas con más capacidades de lectura y escritura;
4
InputStream
La clase que hereda InputSteam se utiliza para introducir datos en el programa
. La unidad básica de los datos de entrada: byte (8 bits)
método básico:
int read( ) throws IOException
int read(byte[ ] buffer) throws IOException
int read(byte[ ] buffer,int offset,int length)throws IOException
void close( ) throws IOException
Nota: El
método de lectura es un método de bloqueo.
Devuelve el número de bytes realmente leídos. Cuando se llega al final del archivo, devuelve -1
5
OutputStream
La clase que hereda OutputStream se utiliza para que el programa genere
datos. Unidad de datos: byte (8 bits)
método básico:
int write(int b) throws IOException
int write(byte[ ] b) throws IOException
int write(byte[ ] b,int offset,int length)throws IOException
void flush( ) throws IOException
void close( ) throws IOException
Flush borrará el caché, es decir, escribirá los datos en caché en el archivo. Cerrar es cerrar el archivo en un programa general. Llame a flush (
) antes de llamar a close () para escribir los datos del búfer en el disco.
6
Reader
hereda la clase Reader y se utiliza para introducir caracteres en el programa.
La unidad de datos es carácter (16 bits)
método básico
int read( ) throws IOException
int read(char[ ] cbuf) throws IOException
int read(char[ ] cbuf,int offset,int length) throws IOException
void close( ) throws IOException
7
Writer
hereda la clase Writer y se utiliza para generar caracteres
del programa . La unidad de datos es el carácter (16 bits). El
método básico
void write(int c) throws IOException
void write(char[ ] cbuf) throws IOException
void write(char[ ] cbuf,int offset,int length) throws IOException
void write(String string) throws IOException
void write(String string, int offset, int length) throws IOException
void close( ) throws IOException
void flush( ) throws IOException
8