Knowledge Base

FIX: FileOutputStream(String,boolean) Functions Incorrectly

Article ID: 178639

Article Last Modified on 9/13/2005


APPLIES TO


This article was previously published under Q178639

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. This problem has been fixed in Internet Explorer 4.01 Service Pack 1, and SDK for Java 2.02.

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 pages on the Microsoft Technical Support site:

Additional query words: FileOutputStream, output, write

Keywords: kbbug kbfix kbsdkjava202fix kbcode KB178639