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. File Handling- JAVA

  2. Game application in CORBA for which player will guess a number between 1 to 100, which will be compared to the random number generated by the class

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

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

  5. Socket program of HTTP Server

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

  7. An applet program to display barchart of given data

  8. Program to show the use of If Statement

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

  10. Program to compute the sum of the digits of a given integer number. eg: I/o=4 then O/p=4+3+2+1=10

  11. Program to read rollno, marks of sub1,sub2 and sub3 and on basis of that display result

  12. Program to show an example of creating a String object from a StringBuffer Object

  13. Program of telnet server - client

  14. Program for calculating area of a circle on server side,when a client sends request along with given radius and then displaying result on client side

  15. Program to delete mth element from an input string

  16. An applet program to perform quick sort

  17. Program to extract a portion of a character string and print the extracted string

  18. Program of storing and retrieving integers using data streams on a single file

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

  20. Program to declare and initialize Integer variables and print them on the Standard Output Device

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