0

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?

  • *"same folder that my jar file is at"* To clarify: 1) a folder is a windowed OS form of a directory. 2) The best way to get a documentation file (MS Word or otherwise) to the user is to include it **in** the Jar. 3) A resource in a Jar is accessible via `URL` but not `File`. 4) If it is necessary for the document to be updated, it needs to be copied from the Jar (where it is read-only) to the local file system (as a `File`). 5) A better location than *"same folder"* is a (sub) directory of `user.home`. - So with those points in mind, could you clarify the question above? As-is, very confusing. – Andrew Thompson Feb 14 '22 at 11:44

1 Answers1

0

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");`
Atomos
  • 1
  • 1