GeekInterview.com
Series: Subject: Topic:
Question: 28 of 78

How to run doc file in Java?

Asked by: Interview Candidate | Asked on: Dec 27th, 2005
Showing Answers 1 - 4 of 4 Answers
Guest

Answered On : Jan 3rd, 2006

The question is a bit ambigiuos.I understood that you want to open doc(MS-WORD) file using java program.Am I Right?

Anyhow if u want to open non-java application,You can use class java.lang.Runtime class.

The following java program opens a word file named 'OAFAQs.doc'.

import java.io.*;

public class Doc
{
 public static void main(String[] str)throws IOException
 {
  Runtime rt = Runtime.getRuntime();
  Process p = rt.exec("C:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.exe   OAFAQs.doc");
 }
}

Here the "C:\\Program Files\\Microsoft Office\\OFFICE11\\WINWORD.exe" is the executable file for MS-WORD.

  
Login to rate this answer.
Sreeni

Answered On : Feb 21st, 2006

There are two kinds of Javadoc comments: class-level comments, and member-level comments. Class-level comments provide the description of the classes, and member-level comments describe the purposes of the members. Both types of comments start with /** and end with */.

  • @author: Describes the author of the document. Used in class-level comments
  • @param: Describes a parameter of a method or constructor.
  • @return: Describes the return type of a method.
  • @throws: Describes an exception a method may throw.
  • @exception: Describes an exception.

  
Login to rate this answer.
anshuman

Answered On : Apr 15th, 2007

I have used your source code
it opens the word software but it does not open the file
it is saying that permission is not there
pls provide some help on it

  
Login to rate this answer.

Here is the correct code for this. Save anywhere your document file it search and open.

import java.io.*;
public class Example {

    public static void main (String[] args) throws IOException
        {
            Runtime rt=Runtime.getRuntime();
   
             rt.exec( "C:Program FilesMicrosoft OfficeOFFICE14WINWORD.exe notes.doc" );  
   
        }
}

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.