Java Tutorial

 
 
 
 
import java.io.*;

class  countChar
{
    public static void main(String[] args) throws IOException
    {
           File f = new File(args[0]);
           FileOutputStream fos = new FileOutputStream(f);
           for (int i=0;i<5;i++ )
           {
                 fos.write((int)(Math.random()*4));
           }
           fos.close();

           FileInputStream fis = new FileInputStream(f);
           int ch;
           int c[] = new int[5];
           for (int i=0;i<c.length ;i++ )
           {
                 c[i]=0;
           }
           while((ch=fis.read())!=-1) {
                  switch (ch)
                  {
                  case 0: 
                                 c[0]=c[0]+1;
                                 break;
                  case 1:
                                 c[1]=c[1]+1;                
                                 break;
                  case 2:
                                 c[2]=c[2]+1;                  
                                 break;
                  case 3:
                                 c[3]=c[3]+1;                               
                                 break;
                 case 4:
                                 c[4]=c[4]+1;
                                 break;
                  }
                 System.out.println(ch);
            }
            System.out.println(\"\\n\\n\\nCounting of Characters\\n\");
            for (int i=0;i<c.length ;i++ )
            {
                 System.out.println(\"count for \"+i+\"    : \" +c[i]);
            }
            fis.close();
    }
}

    Related Post:
  1. Program that maintains employee database of an education system

  2. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

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

  4. Write a class whose objects holds a current value and have a method to add that value, printing the new value

  5. An applet program to take user input and display

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

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

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

  9. Program that accepts a shopping list of five items from the command line and stores them in vector

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

  11. Even no or Prime no?????

  12. An applet program showing Clicked Event on canvas

  13. Program to show an example of Polymorphism

  14. Program of linear search

  15. Program to show the use of Do-While Loop

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

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

  18. Application for counting factorial of a given number

  19. Develop a game application in CORBA for which the player will guess a number between 1 to 100, which will be compared to the random number generated b

  20. Simple Applet which will show life cycle of an Applet

 
 
Didn't find what you were looking for? Find more on File handling program to count number of characters in a file