Random IO : RandomAccessFile « File Input Output « Java






Random IO

   
import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomIOApp {
  public static void main(String args[]) throws IOException {
    RandomAccessFile file = new RandomAccessFile("test.txt", "rw");
    file.writeBoolean(true);
    file.writeInt(123456);
    file.writeChar('j');
    file.writeDouble(1234.56);
    file.seek(1);
    System.out.println(file.readInt());
    System.out.println(file.readChar());
    System.out.println(file.readDouble());
    file.seek(0);
    System.out.println(file.readBoolean());
    file.close();
  }
}

   
    
  








Related examples in the same category

1.Using the RandomAccessFile class
2.The RandomAccessFile Class
3.Use RandomAccessFile to reverse a file
4.Using a Random Access File
5.A RandomAccessFile object that is tied to a file called employee.dat.
6.Reading UTF-8 Encoded Data
7.Use RandomAccessFile class
8.Appending data to existing file
9.The class demonstrates the use of java.io.RandomAccessFile
10.Readonly RandomAccessFile
11.Translate Charset
12.Use RandomAccessFile to save an object
13.Reverse a file with RandomAccessFile
14.Read from back
15.Using RandomAccessFile to read file saved DataOutputStreamUsing RandomAccessFile to read file saved DataOutputStream