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 show an example of Concatination of Strings

  2. Program to declare, initialize and print an array of characters

  3. An applet program to display sum of two number of textField

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

  5. Program to show an example of Multiple Levels of Inheritance

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

  7. Program in CORBA which takes a long sentence from the client (at least 7 words), passes to the server, server separates out each word

  8. Program to show the use of Conditional AND Operator (&&) in If Statements

  9. Program to read bytes from a file

  10. Pass the marks of 10 students from the client side design a servlet, which takes these marks and returns the number of students who obtained first cls

  11. Program to show the use of Logical AND Operator (&) in If Statements

  12. Program to show the use of Nested If-Else Statements

  13. Corba program of game

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

  15. Program which will read a string and rewrite it in the alphabetical order

  16. Program to display reverse $ tree

  17. Program to show the use of Increment and Decrement Operators

  18. File handling program to copy characters from one file to another

  19. Program to read input from the Standard Input Device

  20. RMI application for getting the final total price of the shopping list with some of the following items and quantities chosen by the user

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