title: read a doc and rewrite with Apache POI ,but fail to open with office
body: <p>I'm trying to modify a doc with Apache POI in Java.</p>
  
  <p>At first the test.doc cannot be read with a exception raised up :</p>
  
  <p>"org.apache.poi.poifs.filesystem.NotOLE2FileException: Invalid header signature; read 0x6576206C6D783F3C, expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document
  "</p>
  
  <p>So I saved the doc as "word 97 - 03" format,and then POI can read the doc properly.</p>
  
  <p><strong>But when I try to rewrite the content to a new file with nothing changed, the file output.doc cannot be opened by MS Office.</strong></p>
  
  <p>When I make a new doc myself with MS Office, the POI works well, everything goes right.</p>
  
  <p>So the problem is "test.doc".</p>
  
  <p>The test.doc is generated by some sort of a program which I can't access the code,so I don't know what goes wrong.</p>
  
  <p>My question is : </p>
  
  <p><strong>1.As test.doc can be read by MS Office why can't POI without saving as a new format doc?
  2.As the POI can read the doc, why it cannot write back to a new file(MS Office can't open)?</strong></p>
  
  <p>Here is my code:</p>
  
  <pre><code>    FileInputStream fis = null;
      try {
          fis = new FileInputStream("test.doc");
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      POIFSFileSystem pfs = null;
      try {
          pfs = new POIFSFileSystem(fis);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      HWPFDocument hwdf = null;
      try {
          hwdf = new HWPFDocument(pfs);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      FileOutputStream fos = null;
      try {
          fos = new FileOutputStream(new File("output.doc"));
      } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      try {
          hwdf.write(fos);
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }finally {
  
      }
  
      try {
          fos.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      try {
          fis.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      try {
          pfs.close();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>