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 While Loop

  2. Program to show the use of operator (&gt;&gt;&gt;) Shift Right, filling with zeros from the left

  3. An applet program of linear sort

  4. An applet program to perform quick sort

  5. Program to show an example of Calling a Base Class Method from a Derived Class

  6. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

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

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

  9. Program of UDP datagram

  10. Program using session tracking capability of Servlets, which displays information of current user session by HttpServletRequest object

  11. An applet program to display alternate filled and empty circle that to in row and column format

  12. Even number ,Prime no. ,Factorial of a number

  13. Program to show an example of Arrays of String

  14. Program to show an example of overloading constructors in a class to initialize its data members

  15. Program of an applet to illustrate BarChart

  16. An applet program to display moving banner

  17. Corba program to Write a Echo server and client with UDP server and client

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

  19. Socket program of multi client chat server

  20. An applet program showing Clicked Event on canvas

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