ProgramacionFacil

UNIDAD 6:PROGRAMACION JAVA REGISTROS Y ARCHIVOS DIRECTOS

TEMA 1: JAVA INTRODUCCION ARCHIVOS DISCOS


SE DICE QUE UN ARCHIVO ES DE ACCESO U ORGANIZACION DIRECTA CUANDO PARA ACCEDER A UN REGISTRO N CUALESQUIERA NO SE TIENE QUE PASAR POR LOS N-1 REGISTROS ANTERIIORES.

Como se observa de esta definición los archivos directos tienen una gran ventaja( son mucho mas rapidos) cuando se comparan con los archivos de acceso u organizacion secuencial estudiados en la unidad anterior.

Aunque lo anterior no quiere decir que son mejores que los secuenciales, es decir es el propio problema planteado quien exigira una solucion u otra, por ejemplo si se quiere construir un archivo para almacenar los datos de un guestbook, si se construye de manera directa seria muy rapido pero si lo construimos de manera secuencial, se podran almacenar datos con cantidades de información mas adecuados al problema.

Es decir un archivo de acceso directo tiene que tener sus registros o renglones de un tamaño fijo o predeterminado de antemano.

En java archivos de acceso directo pertenecen a la clase RANDOMACCESSFILE esta clase contiene muchas propiedades algunas de las cuales se muestran aqui, estas propiedades se estaran usando mucho en esta unidad.

Un archivo de acceso directo permite posicionar el apuntador de interno de registros, a cualquier registro determinado sin necesidad de pasar por todos los registros anteriores, usando las siguientes funciones.

Constructor Summary
RandomAccessFile”(“File “file,” String “mode)“
Creates a random access file stream to read from, and optionally to write to, the file specified by the “File” argument.
RandomAccessFile”(“String “name,” String “mode)“
Creates a random access file stream to read from, and optionally to write to, a file with the specified name.
Method Summary
“void” close”()“
Closes this random access file stream and releases any system resources associated with the stream.
FileDescriptor getFD”()“
Returns the opaque file descriptor object associated with this stream.
“long” getFilePointer”()“
Returns the current offset in this file.
“long” length”()“
Returns the length of this file.
“int” read”()“
Reads a byte of data from this file.
“int” read”(byte[] b)“
Reads up to “b.length” bytes of data from this file into an array of bytes.
“int” read”(byte[] b, int off, int len)“
Reads up to “len” bytes of data from this file into an array of bytes.
“boolean” readBoolean”()“
Reads a “boolean” from this file.
“byte” readByte”()“
Reads a signed eight-bit value from this file.
“char” readChar”()“
Reads a Unicode character from this file.
“double” readDouble”()“
Reads a “double” from this file.
“float” readFloat”()“
Reads a “float” from this file.
“void” readFully”(byte[] b)“
Reads “b.length” bytes from this file into the byte array, starting at the current file pointer.
“void” readFully”(byte[] b, int off, int len)“
Reads exactly “len” bytes from this file into the byte array, starting at the current file pointer.
“int” readInt”()“
Reads a signed 32-bit integer from this file.
String readLine”()“
Reads the next line of text from this file.
“long” readLong”()“
Reads a signed 64-bit integer from this file.
“short” readShort”()“
Reads a signed 16-bit number from this file.
“int” readUnsignedByte”()“
Reads an unsigned eight-bit number from this file.
“int” readUnsignedShort”()“
Reads an unsigned 16-bit number from this file.
String readUTF”()“
Reads in a string from this file.
“void” seek”(long pos)“
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
“void” setLength”(long newLength)“
Sets the length of this file.
“int” skipBytes”(int n)“
Attempts to skip over “n” bytes of input discarding the skipped bytes.
“void” write”(byte[] b)“
Writes “b.length” bytes from the specified byte array to this file, starting at the current file pointer.
“void” write”(byte[] b, int off, int len)“
Writes “len” bytes from the specified byte array starting at offset “off” to this file.
“void” write”(int b)“
Writes the specified byte to this file.
“void” writeBoolean”(boolean v)“
Writes a “boolean” to the file as a one-byte value.
“void” writeByte”(int v)“
Writes a “byte” to the file as a one-byte value.
“void” writeBytes”(“String “s)“
Writes the string to the file as a sequence of bytes.
“void” writeChar”(int v)“
Writes a “char” to the file as a two-byte value, high byte first.
“void” writeChars”(“String “s)“
Writes a string to the file as a sequence of characters.
“void” writeDouble”(double v)“
Converts the double argument to a “long” using the “doubleToLongBits” method in class “Double”, and then writes that “long” value to the file as an eight-byte quantity, high byte first.
“void” writeFloat”(float v)“
Converts the float argument to an “int” using the “floatToIntBits” method in class “Float”, and then writes that “int” value to the file as a four-byte quantity, high byte first.
“void” writeInt”(int v)“
Writes an “int” to the file as four bytes, high byte first.
“void” writeLong”(long v)“
Writes a “long” to the file as eight bytes, high byte first.
“void” writeShort”(int v)“
Writes a “short” to the file as two bytes, high byte first.
“void” writeUTF”(“String “str)“
Writes a string to the file using UTF-8 encoding in a machine-independent manner.

Fuente: JAVA SUN

 




 


Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

Politica de Privacidad