BUG: FileOutputStream(String,boolean) Functions Incorrectly

Last reviewed: January 29, 1998
Article ID: Q178639
The information in this article applies to:
  • Microsoft Win32 Virtual Machine for Java
  • SDK for Java, versions 2.0, 2.01

SYMPTOMS

When trying to write data to a file that already has some data written using FileOutputStream(String, boolean), the resulting output does not append the text properly.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new Java Project and include the following class:

          import java.io.*;
          class Test
          {
    

             public static void main(String args[])
             {
                try
                {
                  FileOutputStream fos = new FileOutputStream("test.txt",
                  true);
                  PrintWriter pw = new PrintWriter(fos);
                  pw.print("This is a test of the "+
                           "FileOutputStream(String,boolean).\r\n");
                  pw.close();
                  fos.close();
    
                 FileOutputStream fos2 = new FileOutputStream("test.txt",
                 true);
                 PrintWriter pw2 = new PrintWriter(fos2);
                 pw2.print("Appended text.\r\n");
                 pw2.close();
                 fos2.close();
                }
                catch (IOException ex)
                {
                   System.out.println(ex);
                }
    
             }
          }
    
    

  2. Build the above code and execute it. If you look at the Test.txt file that was created, you will notice that the output looks like:

          Appended text.
          f the FileOutputStream(String,boolean).
    

  3. The correct output should be as follows:

          This is a test of the FileOutputStream(String,boolean).
          Appended text.
    

REFERENCES

For more information on java.io.PrintWriter, please refer to the JDK1.1 documentation.

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: FileOutputStream, output, write

Keywords : kbcode AWTPkg
Technology : kbInetDev internet
Version : WINDOWS:2.0,2.01
Platform : WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.