3 Replies Latest reply: May 4, 2007 5:59 AM by 807606 RSS

    Not writing data into text file....

    807606
      Hi all,

      iam using buffered writer to write data into a text file.

      BufferedReader inputstream = new BufferedReader(new FileReader("C:\\CarInputData.txt"));
                     
           BufferedWriter     outputstream = new BufferedWriter(new FileWriter("C:\\CarOutputData.txt"));

      outputstream.write("Car Model :" + st.nextToken());

      But some how the data is not written?Where am i going wrong
        • 1. Re: Not writing data into text file....
          807606
          catch (FileNotFoundException e)
                         {
                         System.out.println("File not found!");
                         try
                         {
                         //inputstream.close();
                         outputstream.close();
                         }
                         catch (IOException ioe) {} // disregard close failure
                         }

          Iam closing the outputstream in the catch block?Does it cause any problem?

          The output is empty.Dat not written.
          • 2. Re: Not writing data into text file....
            807606
            whare am i going wrong?
            • 3. Re: Not writing data into text file....
              807606
              If you close your file in the catch block you will only close it when your input file does not exist. This does not make any sense. You need to close them once you have finished accessing them.

              It's a bit like saying only close the door when you can't find it.
              try {
                //Code to execute (1)
              } catch (Exception e) {
                //Code to execute when (1) throws an exception
              }