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 to show the use of Bitwise Operator (&) AND

  2. Program that reads and writes random access file

  3. Program to show an example of using a Non-Static Nested Class

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

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

  6. Program to generate SQUARE ROOT table

  7. Program to check the start and end of a String

  8. Corba program of date operations

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

  10. Program that accepts a shopping list of items from the command line and stores them in a vector. Also provide facility to perform operation

  11. Write a program for restaurant

  12. Program that will read real number from the keyboard and print the following output in one line: small Integer not less The Given Number Largest Int

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

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

  15. Program to show an example of using user-defined package in a program

  16. Program to compare Strings by compring successive corresponding characters, starting with the first character in each String

  17. File Handling- JAVA

  18. Program to show the use of operator (&gt;&gt;) Shift Right, propagating the sign bit from the left

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

  20. Program of an applet to illustrate BarChart

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