Java RandomAccessFile .writeShort (int v)

Syntax

RandomAccessFile.writeShort(int v) has the following syntax.

public final void writeShort(int v)   throws IOException

Example

In the following code shows how to use RandomAccessFile.writeShort(int v) method.


//  ww w.ja va  2s  . c om

import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         short s = 15;

         RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

         raf.writeShort(s);

         raf.seek(0);

         System.out.println(raf.readShort());

         raf.seek(0);

         raf.writeShort(20);

         raf.seek(0);

         System.out.println(raf.readShort());
         raf.close();
      } catch (IOException ex) {
         ex.printStackTrace();
      }

   }
}