Page 621 - ComputerScience_Class_11
P. 621

18              reader.close();

                   19              reader = new BufferedReader(new FileReader(inputFile));
                   20          BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));

                   21

                   22              System.out.println("\nAfter:");

                   23              while ((line = reader.readLine()) != null)

                   24              {

                   25                  if (!line.contains("a"))

                   26                  {
                   27                      writer.write(line);

                   28                      writer.newLine();

                   29                      System.out.println(line);

                   30                  }

                   31              }

                   32
                   33              reader.close();

                   34              writer.close();

                   35          }

                   36      }




                       Note: To run this program, you must have the input.txt file with sample data in the folder where your
                       project is saved. Otherwise, the Java compiler will report an error.




                 The output of the preceding program is as follows:

                       BlueJ: Terminal Window - Java
                   Options

                  Before:
                  The quick brown fox.
                  Apple is a fruit.
                  Bananas are yellow.


                  After:
                  The quick brown fox.




                                                                                                Internal Assessment  619
   616   617   618   619   620   621   622   623   624   625   626