Opening a word document in Java

HI
I am new to java. I am trying to open a word document when user press the button. I just want to open the document that exists on my computer. I have tried using exec() method of Runtime class. But I was not succeed. Here the code that I have used.
public void actionPerformed(ActionEvent ae)     {
     String str = ae.getActionCommand();
     if(str.equals("Search")){
          Runtime r = Runtime.getRuntime();
          Process p = null;
          try{
               p = r.exec("C:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.exe C:\\Resume\\coverletter.doc");
          }catch (IOException e){
               System.out.println("Error");
repaint();
Here "Search" is th name of Button.
So if anyone have a solution please help me regarding to this.
Thank you

Use java.awt.Desktop (available since Java 6), it provides a .open() method that will open any file with the users associated application (so no dangerous hardcoding of application paths necessary).
If you insist on using Runtime.exec, then you must read [When Runtime.exec() wont|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html].

Similar Messages

  • HOW TO OPEN WORD DOCUMENT FROM JAVA???

    hi everyone! Can you please help me to come with this problem? Let me to set my main target I want to achieve:
    1) In my program user should first press a button;
    2) Then already created Word Document should be opened (I DO NOT NEED to open that Word Document in Java or something like JField). Just simply it should be opened as a Microsoft Word Document.
    I DO NEED YOUR HELP! PLEASE HELP ME....!

    Running cmd using the exec is also a windows only solution, there is no "more" or "less" it that solution compared to the rundll.
    Since word is a windows format its pretty obvious that the application is ran under windows platform.
    If you are running on a different platform (maybe using open office you can open word documents, i'm not sure) you might want to use the JDIC library (https://jdic.dev.java.net/) which enables you to open/edit/browse such files using the default viewer/editor/browser of the system you are working on.
    Look at the org.jdesktop.jdic.desktop.Desktop object for these methods.
    You can also find the Desktop object in J2SE6 but its still in beta.

  • Open a word document from a Java Application

    Hi,
    Can I open a word document from a java GUI apllication and point to a bokkmark automatically in the word document when opened.

    See this thread:
    http://forum.java.sun.com/thread.jspa?threadID=228332&messageID=810684

  • Opening a Word Document with a Java program in Windows

    When running a Java program in Windows, is it possible to have a button where when it is clicked it will open a Word document?
    If so, is it hard and can someone tell me how to do it??
    Thanks

    try this instead of Excel.exe you have to use Word.exe
    1. Declare your button
                   JButton butexlcom = new JButton("Carnet Offre");
                   butexlcom.addActionListener( new ButExlCommercial(msgout));
                   butexlcom.setBounds(215,510,110,30);
                   c.add( butexlcom );
    2. run your word document.
    class ButExlCommercial implements ActionListener {
         private JTextArea msgout;
         public ButExlCommercial( JTextArea msg) {
         msgout = msg;
         public void actionPerformed( ActionEvent e ) {
              try {
                   Runtime.getRuntime().exec("c:\\Program Files\\Microsoft Office\\Office\\Excel.exe NameWordDocument");
              catch(Exception en) {
                   msgout.append( "\n*** PROBLEME WORD ***\n" );
    }

  • Open/save word document in jsp

    I can open a word document in jsp but i don't know how to save and close it to where i want again inside same jsp.
    I find a code that do thing i want to do but it was written in vb script.
    How can i convert vb code below to java / jsp?
    Dim wrdApp As Word.Application
    MyStr = Format(dtMyDate, "mmm dd, yyyy") & ".doc"
    Set wrdApp = New Word.Application 'released first resources
    With wrdApp
    .Documents.Add "normal.dot", , , True
    strPatientName = txtName.Text
    strFileName = "c:\MJCC\Lab\" & strPatientName & "_" & MyStr
    .ActiveDocument.SaveAs strFileName
    .ActiveDocument.Close
    .Quit
    End With
    Set wrdDoc =Nothing

    <%@ page contentType="application/vnd.ms-excel" language="java"%>
    <meta http-equiv="Content-Type" content="application/vnd.ms-excel; charset=iso-8859-1">
    by using this 2 codes, when i run this page, it will pop up a box for me to save the jsp file..
    i'm able to save it in xls / csv format...
    so, mayb you can try change the ms-excel to ms-word or something else..
    hope this is useful...

  • Opening a word document for editing with webdav

    I'm not sure if this is the correct place for this question..
    I am attempting to open a word document, which resides in a webdav folder from web app. I need IE to start word and open the original document from the webdav folder and allow the user to make changes to the document and save it back to the webserver.
    Wep app this http://www.javatalks.ru/go.php?uri=http://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
    I've got it to open the document but it seemed to have copied the document to my temporary internet files folder and opened the copy from there. The original file name is "test.doc" but the opened temprary file is "test[1].doc" and so on. How can I get it to open the original document for editing?
    Any help would be appreciated..

    Not sure about payment options but you can check for yourself at http://success.adobe.com/en/na/sem/products/acrobat/feature.html

  • I am changing from Word to Pages. I have created my custom template with all my styles etc and that is what comes up when I go for a New Document. Fine. How do I get it to use the same Custom Template when I use Pages to open a Word document?

    I am changing from Word to Pages. I have created my custom template with all my styles etc and that is what comes up when I go for a New Document. Fine. How do I get it to use the same Custom Template when I use Pages to open a Word document?

    The template is a document in itself, it is not applied to an existing document whether it is a Pages document or a Word document converted to a Pages document.
    You would need to either copy and paste content, using existing styles, or apply the styles to the converted Word document.
    You can Import the Styles from an existing document and those imported Styles can be used to override the current document's styles:
    Menu > Format > Import Styles
    The process is simplified if the styles use the same names, otherwise you will need to delete the style you don't want and replace it with the one that you do want when asked, then the substitution is pretty straightforward.
    Peter

  • HT202879 how can I open a Word document in Pages 09?

    How can I open a Word document using Pages 09 please? I am trying to open Word documents from a CD using both trying to open in Pages, nd dragging and dropping into the Pages icon in the dock. It tells me, every time, thast the document cannot be opened.

    What happens if you open it in TextEdit or LibreOffice [free]?
    Does it open where you got it from?
    Peter

  • How can I open a word document in C++ with a CNiWordApplication object?

    Hello,
    For an application, i need to open a word document using VisualC++ and CNiWord classes (CNiWordApplication, CNiWordDocument...). I successed to create a new CNiWordDocument with the CNiWordApplication CreateDocument() function. But when using the OpenDocument() I have error message about violation error. Must I create another objet before calling the OpenDocument() function? Is it possible to have an example of code to open a word document?
    Thank you for your help.

    I tried the following code to open a doc file in an MFC application.
    CNiWordApplication word;
    CNiWordDocument doc = word.OpenDocument("c:\\books.doc");
    This worked fine for me. I tried this with Word 2003 and Measurement Studio 7.1
    Try running one of the shipping examples. You can find examples for this under ..\MeasurementStudio\VCNET\Examples\Office\
    Hope this helps.
    Bilal Durrani
    NI

  • Did I miss something in the fine print? I installed Lion and and come to find out, I can no longer open any Word documents or Excel spreadsheets as they are no longer supported (being PowerPC apps).  Seriously?!?!?!?!!   What are my alternatives?

    Did I miss something in the fine print? I installed Lion and and come to find out, I can no longer open any Word documents or Excel spreadsheets as they are no longer supported (apparently because they are PowerPC apps).  Seriously?!?!?!?!!   What are my alternatives?

    Hi Mary and Matthew
    You might find it helpful to "try before you buy" - there is a 30 day free trial offer for Office for Mac 2011, accessible from M's .com website.
    You may be able to use this period to open and resave your old documents in a format that enables you to switch instead to using Apple's iWorks apps moving forward.
    I initially intended to do something similar, but ended up buying Office as it provided an easier way (for me, at least) to continue working with years worth of old emails, letters, spreadsheets and other documents (from my PC days) without risking damage to their integrity, formatting, etc.

  • When I open a word document attachment in mail for IOS 7.1.1 the previous jpeg is showing on the first page. When I open the attachment from mail in mac OS X the jpeg does not appear. Can anyone help?

    When I open a word document attachment in mail for IOS 7.1.1 the previous jpeg is showing on the first page. When I open the attachment from mail in mac OS X the jpeg does not appear. Can anyone help?

    gonsa47 wrote:
    When I open it in pages or word the correct company logo appears.
    Does the mail app display whatever is in the document without the ability to differentiate between hidden or non hidden images?
    The mail app will not display fillable form fields in PDF files that can be seen in real PDF apps. I say real PDF apps because the form fields in PDF apps will not appear in the iBooks app either. IMO, iBooks is not a real PDF app.
    So, I would say that the mail app cannot differentiate between hidden and non hidden items

  • When I try to install abode - it will download but says i have to close firefox before it will install. also i try to open a word document from a website and it will not open - it will only download

    i install abode - it will download but not install and indicates i have to close firefox before it will download. Also, I try to open a word document from a website - it will download but not open.

    You need to close Firefox to install many plugins, including those from Adobe.
    As for the Word downloads, see the changing downloads action section of this link - https://support.mozilla.com/kb/Managing+file+types

  • How do i open a word document as a sub-VI?

    i need  to use/open a word document or a web page as a sub-VI. All im able to do now is upload it as a text format and it dosen't look to presentable.
    i have been trying the Active function and it dosent seem to work as i am not to familiar with it. i need suggestion to  overcome this problem
    thanks

    to: smercurio_fc
    i am not able to view the example you suggested. it sounds interesting pls suggest a different way.
    i want to upload a word document or a repective web page can u pls suggest a solutioj
    thanks
    pravin

  • How do I open a WORD document which is password protected?

    I need to open a word document, which is password protected.  I can't even get to a page that'll allow me to put in the password!!!  Can anyone advise how I can do this?
    Thanks.

    Hi JoeyR.
    Thanks for your reply.
    I get the following message when I try to open the document: "The Word document is password protected and can’t be imported".
    I've looked at the Open Office software, as you suggested, but it seems confusing.  I'll give it a try, though, as I'm wasting too much time!
    Fingers Crossed!

  • Opening a Word Document in Pages - floating objects not supported

    I am trying to open a Word document in pages. It is a table of labels with artwork and text. Pages tells me that floating objects inside cells are not supported and were deleted. I've tried making them inline with text in the original document and then opening in Pages, but then I can't make them floating again. Anyone know how to do this? I really don't want to have to buy a Microsoft product!

    Don't buy a M…soft product, use the free openOffice or the free neoOffice.
    Yvan KOENIG (VALLAURIS, France) samedi 18 décembre 2010 18:09:50

Maybe you are looking for

  • "Your Startup disk is almost full"  How do you fix this?

    Someone please help! More and more frequently my Mac Mini (Mac OS X Version 10.5.8) say that "My startup disk is almost full" So I deleted everything non critical to the maintenance and function of my Mac Mini but still it tells me that my "Start up

  • Flow Activity Exception Handling Problem

    Hi, I am using Flow Activity in my Bpel Process, i am getting some exception in one of flow, but other flows are working fine. Even i have included Catch block for other flow still i am getting fault response. Please suggest me how to do exception ha

  • Freight charges in delivery

    Hi all, We are running release 5.0 and have a problem with copying freight from the delivery header into the billing document. The condition amount is copied over but not the condition base value and condition value. Has anyone experienced a similar

  • Question about ALTER SYSTEM ARCHIVE LOG START

    Good morning, I'm trying (unsuccessfully) to get my database to be in archive log mode. These are the steps I followed: SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down. SQL> startup mount; ORACLE instance star

  • F1 - F8 no longer work

    This is a dual G5 2ghz, not a powerbook. Ever since 10.4.3 my F keys don't work in my main user account. It's not a keyboard issue, I've swapped it out. I can switch to another user and they work fine, but not in my user. When I hit F1 & f2 I hear an