user2532605
user2532605

Reputation:

Open file with default associated program using Java/C++

I have file, lets call it document.doc, and I want to open it with MS Word or some other program (default). What would be solution (in C++ or Java) be?. I prefer Java but I will need C++ later, so I'm asking for both.

Upvotes: 2

Views: 2859

Answers (2)

ST3
ST3

Reputation: 8946

With C++ should be this: ShellExecute(0, 0, L"document.doc", 0, 0 , SW_SHOW );

Java: java.awt.Desktop.getDesktop().open("document.doc");

Upvotes: 2

Andrew Thompson
Andrew Thompson

Reputation: 168825

Java:

Desktop.getDesktop().open(file);

See Desktop.open(File) for details beyond:

Launches the associated application to open the file.

Upvotes: 3

Related Questions