Java RandomAccessFile .writeBytes (String s)

Syntax

RandomAccessFile.writeBytes(String s) has the following syntax.

public final void writeBytes(String s)   throws IOException

Example

In the following code shows how to use RandomAccessFile.writeBytes(String s) method.


/*from  w w  w.  j ava  2  s  .  c o m*/
import java.io.*;

public class Main {

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

         raf.writeBytes("Hello World from java2s.com");

         raf.seek(0);

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

         raf.seek(0);

         raf.writeBytes("This is an example from java2s.com");

         raf.seek(0);

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

   }
}