kAWT Version 0.96

java.io
Class RandomAccessFile

java.lang.Object
  |
  +--java.io.RandomAccessFile

public class RandomAccessFile
extends Object

Instances of this class support both reading and writing to a random access file.


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.
 int getFilePointer()
          Returns the current offset in this file.
 int length()
          Returns the length of this file.
 byte read()
          Reads a byte of data from this file.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 int read(byte[] b, int start, int len)
          Reads up to len bytes of data from this file into an array of bytes.
 String readLine()
          Reads the next line of text from this file.
 void seek(int pos)
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 void setLength(int newLength)
          Sets the length of this file.
 void write(byte b)
          Writes the specified byte to this file.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 void write(byte[] b, int offset, int len)
          Writes len bytes from the specified byte array starting at offset off to this file.
 void writeChars(String s)
          Writes a string to the file as a sequence of characters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessFile

public RandomAccessFile(String name,
                        String mode)
                 throws IOException
Creates a random access file stream to read from, and optionally to write to, a file with the specified name.
Parameters:
name - the system-dependent filename.
mode - the access mode.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, or cannot be opened or created for any other reason

RandomAccessFile

public RandomAccessFile(File file,
                        String mode)
                 throws IOException
Creates a random access file stream to read from, and optionally to write to, the file specified by the File argument.
Parameters:
file - the file object.
mode - the access mode.
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, or cannot be opened or created for any other reason
Method Detail

close

public void close()
           throws IOException
Closes this random access file stream and releases any system resources associated with the stream.
Throws:
IOException - if an I/O error occurs.

getFilePointer

public int getFilePointer()
                   throws IOException
Returns the current offset in this file.
Returns:
the offset from the beginning of the file, in bytes, at which the next read or write occurs.
Throws:
IOException - if an I/O error occurs.

length

public int length()
           throws IOException
Returns the length of this file.
Returns:
the length of this file, measured in bytes.
Throws:
IOException - if an I/O error occurs.

read

public byte read()
Reads a byte of data from this file.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! Method in J2SE is "public int read()" !!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

read

public int read(byte[] b,
                int start,
                int len)
         throws IOException
Reads up to len bytes of data from this file into an array of bytes.
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the file has been reached.
Throws:
IOException - if an I/O error occurs.

write

public void write(byte[] b,
                  int offset,
                  int len)
           throws IOException
Writes len bytes from the specified byte array starting at offset off to this file.
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs.

readLine

public String readLine()
                throws IOException
Reads the next line of text from this file.
Returns:
the next line of text from this file, or null if end of file is encountered before even one byte is read.
Throws:
IOException - if an I/O error occurs.

seek

public void seek(int pos)
          throws IOException
Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! Method in J2SE is "public void seek (long pos)" !!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Parameters:
pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws:
IOException - if an I/O error occurs.

setLength

public void setLength(int newLength)
               throws IOException
Sets the length of this file.
Parameters:
newLength - The desired length of the file
Throws:
IOException - If an I/O error occurs

write

public void write(byte b)
           throws IOException
Writes the specified byte to this file.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! Method in J2SE is "public void write (int b)" !!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Parameters:
b - the byte to be written.
Throws:
IOException - If an I/O error occurs

writeChars

public void writeChars(String s)
                throws IOException
Writes a string to the file as a sequence of characters.
Parameters:
s - a String value to be written.
Throws:
IOException - If an I/O error occurs

kAWT Version 0.96