0

I’m really confused. I have combo box that has word doc names, when I select one of them the app should be replace some text in that selected word doc, etc. enter image description here

The problem I have is when I convert the app to .jar the word doc is empty, although I added resource file into my project folder & uses the code: enter image description here

File file = new File(getClass().getResource("resources/Template1.docx").getFile());
    WordDocument doc = new WordDocument(file.toString());

My question is about: how to store files (word doc) into my project, so when I execute it & make it as desktop application it'll remains there?

(I'm using netbeans, JWord library)

mona
  • 53
  • 1
  • 1
  • 7

1 Answers1

0

I have found the answer that I was looking for, I'll share here.

First. convert your application to .jar, Run> Clean and Build Project. It'll add your converted java project in your NetBeansProjects> your project folder> dis

Second. Add your folder that contains the files you want to store in java project in dis folder.

enter image description here

Third. Write the code:

            File file = new File("resources/Template1.docx");
            String fileContents  = file.toString();
            WordDocument doc = new WordDocument(fileContents);

where resources is a folder in dis folder that contains your .jar application, and Template1.docx is the file you want to store.

(I'm using netbeans, JWord library)

mona
  • 53
  • 1
  • 1
  • 7