Documentos de Académico
Documentos de Profesional
Documentos de Cultura
ObjectInputStream
ObjectOutputStream
Clase ObjectOutputStream
Es usada para escribir en un archivo binario.
Sintaxis:
public ObjectOutputStream (OutputStream objeto)
Ejemplo de su uso:
new ObjectOutputStream(new FileOutputStream (nombreArchivo))
Ojo:
Puede generar FileNotFoundException de IOException
Mtodos
public void writeInt(int n) throws IOException
public void writeShort(short n) throws IOException
public void writeLong(long n) throws IOException
public void writeDouble(double x) throws IOException
public void writeFloat(float x) throws IOException
Mtodos
public void writeBoolean(boolean b) throws IOException
public void writeChar(int n) throws IOException
public void writeObject(Objetc objeto) throws IOException
public void close( ) throws IOException
public void flush( ) throws IOException
Clase ObjectInputStream
Sintaxis:
public ObjectInputStream (InputStream objeto)
Ejemplo de su uso:
new public ObjectInputStream (new FileInputStream(nombreArchivo))
Mtodos
public int readInt( ) throws IOException
public short readShort( ) throws IOException
public long readLong( ) throws IOException
public double readDouble( ) throws IOException
public float readFloat( ) throws IOException
public char readChar( ) throws IOException
public boolean readBoolean( ) throws IOException
Mtodos
public String readUTF( ) throws IOException
public void readObject(Objetc objeto) throws ClassNotFoundException,
IOException
public int skipBytes(int n) throws IOException
public void close( ) throws IOException
public void flush( ) throws IOException
Acceso Aleatorio
Si necesitamos un archivo de acceso aleatorio podemos usar la clase
RandomAccesFile, la cual nos va a permitir leer y escribir en el archivo.
Esta clase la encontramos en el paquete java.io.
Sintaxis
public RandomAccessFile(String nombreArchivo, String modo)
public RandomAccessFile(File ObjetoFile, String modo)
Abre el archivo, no lo borra si ya exista y coloca el puntero al inicio del archivo.
Valor de
modo
Significado
rw
Mtodos
public long getFilePointer() throws IOException
public void seek(long location) throws IOException
public long length() throws IOException
public void setLength(long newLength) throws IOException
public void close() throws IOException
public void write(int b) throws IOException
public void write(byte[] a) throws IOException