I need to load an existing docx template and I would like to include the template file inside the jar so there would only be the jar file for the user.

I've tried the following ...

String inputfilepath = (getClass().getResource("/letter.docx")).toString();

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
            .load(new java.io.File(inputfilepath));

However, I think because .load(File) is expecting a File parameter it cannot load the docx. Is there a way to load the file for WordprocessingMLPackage from the resources folder?

Thanks

有帮助吗?

解决方案

Get the resource as an InputStream, then use WordprocessingMLPackage's:

public static WordprocessingMLPackage load(InputStream is)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top