Include doc (word) file that my program uses

296 views Asked by At

I wrote a program with Java and doc.spire.jar that uses a doc file and then generate a new one, after compiling it into the jar file my program needs that doc file in the same directory where the jar file is located.

How do I insert that doc file so it will be inside the jar file created by IntelliJ?

1

There are 1 answers

0
Atomos On

I think it would be better to add it in a package and access it as a stream.

Suppose this organization MyApp- (package) -MainClass MyApp.Sources -Source.docx

Then in your code

Document doc = new Document();
InputStream str=MainClass.class.getRessourceAsStream("Sources/Source.docx");
doc.loadFromStream(str, FileFormat.Docx_2013);
doc.saveToFile("name.docx");`