|
|
The java.io Package - Reading and Writing Files
| Note |
- flush() does NOT guarantee that the contents will be written to disk. To guarantee the data is written to disk use the FileDescriptor method sync()
|
- FileReader and FileWriter read and write 16-bit Unicode characters
- FileInputStream and FileOutputStream read and write bytes
Random Access Files (JPL pg 258)
- the RandomAccessFile class is NOT a subclass of InputStream, OutputStream, Reader or Writer; instead it incorporates all their functionaly plus additional methods by implementing the DataInput and DataOutput interfaces.
| Note |
- You cannot use a RandomAccessFile object where any of the other input and output streams are required.
|
- the class has two constructors
public RandomAccessFile(String name, String mode)
public RandomAccessFile(File file, String mode)
- the mode argument must be either "r" or "rw" to indicate if the file is to be opened for reading only or reading and writing
- if the file is opened for writing and it does not exist; it will be created
- as with the other File streams, a FileDescriptor object is created when the file is opened
- the class allows you to set a read/write pointer to any position in the file
- key methods are:
public long getFilePointer() throws IOException
public void seek(long pos) throws IOException
public void skipBytes(int count) throws IOException
public long length() throws IOException
Source code examples
|