Java RandomAccessFile write int to file

Description

Java RandomAccessFile write int to file

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");

    // Write the file read counter as zero
    raf.writeInt(0);/*from   w w w  . j av a2  s  .c o m*/

    // Write a message
    raf.writeUTF("Hello world!");
    raf.close();
  }
}



PreviousNext

Related