Java IO Tutorial - Java RandomAccessFile .writeChar (int v)








Syntax

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

public final void writeChar(int v)   throws IOException

Example

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

//  w  w  w . ja  v  a  2 s  . c om


import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         int i = 70;
         
         RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

         raf.writeChar(i);

         raf.seek(0);

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

         raf.seek(0);

         raf.writeChar(71);

         raf.seek(0);

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

   }
}