Page 348 - computer science (868) class 11
P. 348

24              pw.close();
                25              bw.close();

                26              fw.close();
                27          }

                28          void countWrd() throws IOException    {
                29              int count=0;

                30              // declaring the classes required to read file
                31              FileReader fr=new FileReader("Poem.txt");
                32              BufferedReader br=new BufferedReader(fr);

                33              StringTokenizer st;

                34              // Checking for end of file
                35              while((pline=br.readLine())!=null)
                36              {

                37                  st=new StringTokenizer(pline," .?!,");
                38                  // creating object of StringTokenizer class

                39                  while(st.hasMoreTokens())
                40                  {

                41                      String w = st.nextToken();      // Extracting words form the file
                42                      if(w.equalsIgnoreCase("divine"))     // Checking for divine

                43                          count++;
                44                  }

                45              } // end of while
                46              System.out.println("Divine occurs "+count+" times");

                47              // closing stream objects
                48              br.close();

                49              fr.close();
                50          }

                51          // main() method to call other methods
                52          public static void main() throws IOException

                53          {
                54              Poems ob = new Poems();

                55              ob.createFile();
                56              ob.countWrd();
                57          } // end of main

                58      }  // end of class


                346346  Touchpad Computer Science-XI
   343   344   345   346   347   348   349   350   351   352   353