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;
// www.j a  va  2s. c om
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.