Java Tutorial

 
 
 
 
import java.io.*;

class  RandRW
{
    public static void main(String[] args) 
    {
         RandomAccessFile file = null;
         try{
             file = new RandomAccessFile(\"rand.txt\",\"rw\");

             //Writing to the file
             file.writeChar(\'V\');
             file.writeInt(999);
             file.writeDouble(99.99);

             file.seek(0);     //Go to the begining
             //Reading from the file
             System.out.println(file.readChar());
             System.out.println(file.readInt());
             System.out.println(file.readDouble());

             file.seek(2);  //Go to the Second Item
             System.out.println(file.readInt());

             //Go to the end and append false to the file
             file.seek(file.length());
             file.writeBoolean(true);

             file.seek(4);
             System.out.println(file.readBoolean());
             file.close();
            }catch(Exception e) {}
        }
}

    Related Post:
  1. Program to read bytes from a file

  2. Corba program of date operations

  3. Program to determine the sum of the following harmonic series for a given value of n

  4. Program to change characters in a StringBuffer objects and to reverse its contents

  5. An applet program to add two numbers where data is entered in TextField

  6. Program to show an example of creating a String object from a StringBuffer Object

  7. Program to show an example of extraction of characters from a StringBuffer objects

  8. An applet program showing Clicked Event on canvas

  9. Corba program to Write a Echo server and client with UDP server and client

  10. Program to extract a portion of a character string and print the extracted string

  11. Program to calculate the frequency for different values of C starting from 0.01 to 0.1 in steps of 0.01

  12. An applet program to display Horizontal Color Bar

  13. Program to show the use of Bitwise Operator (&) AND

  14. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  15. Program to show an example of Polymorphism

  16. Program to show an example of using multiple classes in a program

  17. Program to display Floyds Triangle of a numbers

  18. Program, which creates a three thread. One thread display the numbers from 1 to 5, second thread display the square root of that number etc

  19. Program that maintains employee database of an education system

  20. Application which takes your marks of six subjects from the client side and displays the percentage that you have obtained

 
 
Didn't find what you were looking for? Find more on Program that reads and writes random access file