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 search an element in an array using Linear Search

  2. Program of bubble sort

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

  4. program which takes a long sentence from the client passes to the server,server separates out each word and sends them back to client in reverse order

  5. Program of concatenating and Buffering files

  6. corba program of client and a DNS server where given a URL the server sends back an IP address

  7. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  8. Program to show the use of If-Else Statement

  9. GUI application in java, which enter the details of a student and on the submit display the details of the student

  10. An applet program to display moving banner

  11. File Handling- JAVA

  12. Word list program that reads a text file and makes an alphabetical list of all the words in that file. The list of words is output to another file

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

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

  15. An applet program to display Horizontal Color Bar

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

  17. Program to read command line arguments

  18. CORBA PROGRAM TO GET THE HTML CODE FROM ANY URL

  19. Program to display following things on the client machine a)date and time of the server machine b)date and time of the client machine and difference

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

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