How to create a blank word document using Java



Problem Description

How to create a blank word document using Java.

Solution

Following is the program to create a blank word document using Java.

import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class CreateWordDocument {
   public static void main(String[] args)throws Exception {
      
      //Blank Document
      XWPFDocument document = new XWPFDocument();

      //Write the Document in file system
      FileOutputStream out = new FileOutputStream (
         new File("C:/poiword/createdocument.docx"));
      
      document.write(out);
      out.close();
      
      System.out.println("createdocument.docx written successully");
   }
}

Output

Blank Word
java_apache_poi_word
Advertisements