Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I launch a MS Word document??

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
Hi, I have a java app which I contains a help section.
As a temporary measure I would like users to be able to click a button ("help") and then view a word document with help information inside it.

I have NO idea how you would launch this..perhaps something to do with the Runnable Interface, but that's as far as my guess takes me.

Any and all suggestions are VERY much appreciated!!!
Oxy

we are all of us living in the gutter.
But some of us are looking at the stars.
 
The following code will open the application associated with the file. For Example let say I have a file called "aTxtFile.txt", on my PC ".txt" files are associated with Notepad. So When I run the code below Notepad will open up with that file. In the case of ".Doc" files Microsoft Word will open up.

This is the only way that I know how to perform the above that...

Hope this helps.

Code:
import java.io.IOException;

public class StartMicrosoftWord
{
    public static void main(String[] args)
    {
        String newLine     = System.getProperty("line.separator");
        try
        {
            Runtime.getRuntime().exec("cmd /c start C:\\Sample.doc");
            System.out.println ("Microsoft Word opened Successfully.");
        }
        catch (IOException ioe)
        {
            System.out.println("The was a problem starting Microsoft Word:" + newLine + ioe);
        }
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top