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

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





                340340  Touchpad Computer Science-XI
   337   338   339   340   341   342   343   344   345   346   347