import java.io.File;Run:
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
public class CreateDocument
{
public static void main(String[] args)throws Exception
{
//Word document blank
XWPFDocument document= new XWPFDocument();
//create the document in the specific path by giving it a name
File nv_fichier = new File("nouveauFichier.docx");
FileOutputStream out = new FileOutputStream(nv_fichier);
document.write(out);
out.close();
System.out.println("The document "+ nv_fichier +" has been successfully created");
}
}
The createdocument.docx document was created successfullyRun time indicates that the Word file was created successfully. Java compiles and runs this program to generate an empty Word file named nouveauFichier.docx in the path you specified. In our case, this is the current directory of our project.
Please disable your ad blocker and refresh the window to use this website.