Open a document by clicking a button(Java)

  1. Open a NetBeans project
  2. Add new Frame
  3. I added Tool bar and few buttons hear
  4. When you click 'About' button the pdf file will open
  5. Double click on the button and goto button's actionPerform
  6. Add this code
  7.         try{
                Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+"E:\Projects\Blogs\Java\Post\advance\openDocument\\me.pdf");
            }
            catch(Exception e){JOptionPane.showMessageDialog(null, e);}
    
        
  8. Give your file path correctly !
  9. Important

    • You can open any document using this code.
    • Give your file path corectly

No comments:

Post a Comment