Java IO Tutorial - Java RandomAccessFile(File file, String mode) Constructor








Syntax

RandomAccessFile(File file, String mode) constructor from RandomAccessFile has the following syntax.

public RandomAccessFile(File file,     String mode)     throws FileNotFoundException

Example

In the following code shows how to use RandomAccessFile.RandomAccessFile(File file, String mode) constructor.

import java.io.File; 
import java.io.RandomAccessFile;
/* ww w . j  a v a 2 s  .  com*/
public class Main {
  public static void main(String[] argv) throws Exception {
    RandomAccessFile file = new RandomAccessFile(new File("scores.html"), "rw");
    for (int i = 1; i <= 6; i++) {
      System.out.println(file.readLine());
    }
    file.close();
  }
}
  

The code above generates the following result.