title: How to copy some content in one .docx to another .docx , using POI without losing format?
body: <p>Suppose I have two .docx files, <code>input.docx</code> and <code>output.docx</code> I need to select some of the content in <code>input.docx</code> and copy them to <code>output.docx</code>. The <code>newdoc</code> displays its content in the console seems correct, but I did not get anything in the <code>output.docx</code>, except blank lines.  Can anyone provide advices?</p>
  
  <pre><code>InputStream is = new FileInputStream("D:\\input.docx"); 
  XWPFDocument doc = new XWPFDocument(is);
  
  List&lt;XWPFParagraph&gt; paras = doc.getParagraphs();  
  List&lt;XWPFRun&gt; runs;
  XWPFDocument newdoc = new XWPFDocument();                                     
  for (XWPFParagraph para : paras) {  
              runs = para.getRuns();      
              if(!para.isEmpty())
              {
                  XWPFParagraph newpara = newdoc.createParagraph(); 
                  XWPFRun newrun = newpara.createRun();
                  for (int i=0; i&lt;runs.size(); i++) {                       
                      newrun=runs.get(i);
                      newpara.addRun(newrun);
                  }
              }
          }
  
  
          List&lt;XWPFParagraph&gt; newparas = newdoc.getParagraphs(); 
          for (XWPFParagraph para1 : newparas) {  
              System.out.println(para1.getParagraphText());
          }// in the console, I have the correct information
  
          FileOutputStream fos = new FileOutputStream(new File("D:\\output.docx"));
          newdoc.write(fos);
          fos.flush();
          fos.close();
  </code></pre>