Page 368 - Cs_withBlue_J_C11_Flipbook
P. 368

24                  dou.writeInt(appno);
                25                  dou.writeUTF(name);

                26                  dou.writeDouble(avg);
                27                  System.out.print("Continue y/n");

                28                  ch=sc.next().charAt(0);
                29              }

                30              // closing the objects transfers data in buffer to file permanently
                31              dou.close();
                32              fo.close();

                33          }

                34
                35          void find(int ap) throws IOException
                36          {

                37              // declaring the classes required to read file
                38              FileInputStream fi=new FileInputStream("ComputerSc.Dat");

                39              DataInputStream di=new DataInputStream(fi);
                40              boolean eof=false, found=false;

                41               //  try catch block throws End of File exception when the file is not found
                                     in directory
                42              // or end of file is encountered

                43              try
                44              {

                45                  while(!eof)
                46                  {
                47                      appno=di.readInt();

                48                      name=di.readUTF();

                49                      avg=di.readDouble();
                50                      if(appno == ap)
                51                      {

                52                           System.out.println(appno+"\t"+name+"\t\t"+avg+" Selected for
                                                Computer Sc. Hons.");
                53                          found=true;

                54                      }
                55                  } // end of while

                56              } // end of try





                366366  Touchpad Computer Science-XI
   363   364   365   366   367   368   369   370   371   372   373