Java RandomAccessFile .writeByte (int v)

Syntax

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

public final void writeByte(int v)   throws IOException

Example

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


import java.io.*;
/* w w w  .j a va  2 s  . co  m*/
public class Main {

   public static void main(String[] args) {
      try {
         byte[] b1 = {15, 8};
         
         RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

         raf.writeByte(b1[0]);

         raf.seek(0);

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

         raf.seek(0);

         raf.writeByte(b1[1]);

         raf.seek(0);

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

   }
}