1

I have the File Document.docx and put it in the "src/document/Document.docx" When I use

if(Desktop.isDesktopSupported()){
    try{
        Desktop.getDesktop().open(new File("src/document/Document.docx"));
    } catch(Exception e) {
        e.printStackTrace();
    }
}

it working in the neatbean but when I build it into the dist folder, it not work

so how can I open this file when I already builded it ?

i'm Vietnamese so my english not good, don't laught it .. Thanks :D

HpTerm
  • 8,151
  • 12
  • 51
  • 67

2 Answers2

0

When you are in Netbean, the root directory used to find the files is the project dir. Once you build your project, the root directory is not necessary the same. If you put your .jar in the root of the project, it should work. Otherwise you will have to copy your documment to dist/src/document/Document.docx

Basile Perrenoud
  • 4,039
  • 3
  • 29
  • 52
0

It may helps you: Desktop.getDesktop().open(new File("Actual Directory/Document.docx"));

  • It work! But this is my project, I have to send it to Indian, if they put that folder at different Directory, it also not work :( – user3040408 Dec 12 '13 at 14:09
  • use [JFileChooser](http://stackoverflow.com/questions/18774652/how-to-use-jfilechooser-to-find-a-file-location) then user can chose docx file. – Shahin Khaled Dec 12 '13 at 14:34