Java Tutorial

 
 
 
 
import java.io.*;

class  ReadWritePrimitive
{
    public static void main(String[] args) 
    {
           try{
                FileOutputStream fos = new FileOutputStream(\"data.txt\");
                DataOutputStream dos = new DataOutputStream(fos);

                //Writing primitive data to the data.txt file
                dos.writeInt(2000);
                dos.writeDouble(888.88);
                dos.writeChar(\'V\');
                dos.writeBoolean(false);
                fos.close();
                dos.close();

               //Reading primitive data to the data.txt file
               FileInputStream fis = new FileInputStream(\"data.txt\");
               DataInputStream dis = new DataInputStream(fis);
               System.out.println(dis.readInt());
               System.out.println(dis.readDouble());
               System.out.println(dis.readChar());
               System.out.println(dis.readBoolean());
               fis.close();
               dis.close();
             }catch(Exception e) {}

    }
}

    Related Post:
  1. Program to determine the sum of the following harmonic series for a given value of n

  2. Program to show the use of Break Statement

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

  4. Program using Switch case to compute the net amount to be paid by a customer

  5. Program to display Floyds Triangle of a numbers

  6. CORBA based application for addition of two mathematical expressions of the form (ax + by) and displaying the result on client side

  7. Program that enabled applet calculator

  8. Develop a CORBA based application for addition of two complex numbers and displaying the result on client side

  9. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  10. File handling program to copy bytes from one file to another

  11. Program to declare, initialize and print a String object

  12. An applet program to display moving banner

  13. File handling program to count number of characters in a file

  14. Program to read the price of an item in decimal form (like 75.95) and print the output in paise (like 7595 paise).

  15. Program which creates an Array of character. Make one function with one argument as a character and that function throw a user defined exception

  16. Program of storing and retrieving integers using data streams on a single file

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

  18. Program to represent a bank account

  19. Program to read input from the Standard Input Device

  20. Program that reads and writes random access file

 
 
Didn't find what you were looking for? Find more on Program of reading and writing primitive data