Page 372 - Cs_withBlue_J_C11_Flipbook
P. 372
28 fw.close();
29 }
30 void readFile() throws IOException
31 {
32 // declaring the classes required to read file
33 FileReader fr=new FileReader("Flower.txt");
34 BufferedReader br=new BufferedReader(fr);
35 // Checking for end of file
36 while((fname=br.readLine())!=null)
37 {
38 char c=fname.charAt(0); // Extracting the first character
39 if("AEIOUaeiou".indexOf(c)!= -1) // Checking for vowels
40 System.out.println(fname);
41 } // end of while
42 // closing stream objects
43 br.close();
44 fr.close();
45 }
46 // main() method to call other methods
47 public static void main() throws IOException
48 {
49 Flowers ob = new Flowers();
50 ob.createFile();
51 ob.readFile();
52 } // end of main
53 } // end of class
The output of the preceding program is as follows:
Enter the name of the flower
Rose
Continue y/ny
Enter the name of the flower
Aster
Continue y/ny
Enter the name of the flower
Sunflower
Continue y/ny
Enter the name of the flower
370370 Touchpad Computer Science-XI

