user3293920
user3293920

Reputation: 3

How can I open/execute an external file from within java?

I have searched online and couldn't find a straight answer. I know how to read a file into java to be read or manipulated or even how to delete a file but I don't know how to execute an external file (stored on the user's system).

For instance if I had a list of books and their locations on the user's system. I'd like when the user clicks on a particular button then a pdf or document in a particular location is opened up in the relevant software e.g. adobe document reader or word etc.

How do I do this?

Upvotes: 0

Views: 649

Answers (1)

nachokk
nachokk

Reputation: 14413

You can use Desktop class.

the Desktop API (java.awt.Desktop) API, which allows Java applications to interact with default applications associated with specific file types on the host platform.

Read more here How to integrate with the desktop class

Upvotes: 8

Related Questions