Java Tutorial

 
 
 
 
import java.io.*;

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

               for (int i=0;i<20 ;i++ )  //for writing 20 integers to RandData.txt file
               {
                    dos.writeInt((int)Math.random() * 100);
               }
               fos.close();
               dos.close();

               //For Reading Data
               FileInputStream fis = new FileInputStream(\"RandData.txt\");
               DataInputStream dis = new DataInputStream(fis);
               for (int i=0;i<20 ;i++ )
               {
                    int n = dis.readInt();
                   System.out.print(n + \"  \");
               }
               fis.close();
               dis.close();
             }catch(Exception e) {}
    }
}

    Related Post:
  1. Program to declare, initialize and print an array of integers

  2. Biological Sequence Allignment Using Dynamic Programing

  3. Program to show an example of using constructors in a class to initialize its data members

  4. Program to show the use of Bitwise Operator (|) OR

  5. Program to show an example of Arrays of String

  6. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

  7. 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..

  8. An applet program to find maximum of three numbers using textField

  9. Program of creating a file using text fields in windows

  10. Program sets up a String variable containing a paragraph of text of your choice. Extract the words from the text and sort them into alphabetical order

  11. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  12. Program for Thread Priority

  13. Corba program of game

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

  15. 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

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

  17. Program to copy the elements of an array into another array in reverse order and print them

  18. Program to show an example of Copying i.e. Clonning Objects

  19. Program to print a string on Standard Output Device

  20. An applet program that display blinking rectangle

 
 
Didn't find what you were looking for? Find more on Program of storing and retrieving integers using data streams on a single file