Java RandomAccessFile open for read and write

Description

Java RandomAccessFile open for read and write


import java.io.RandomAccessFile;

public class Main {
  public static void main(String[] args) throws Exception {
    // Open the file in read-write mode
    RandomAccessFile raf = new RandomAccessFile("Main.java", "rw");

    int counter = raf.readInt();
    String msg = raf.readUTF();/*from  w w w  . j ava2  s.  co  m*/

    System.out.println("File Read Counter: " + counter);
    System.out.println("File Text: " + msg);

    raf.close();
  }
}



PreviousNext

Related