Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to open a file using method of exec() Runtime class

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
I want to open text (.txt) file using notepad or word (
.doc)file in MSWORD using exec() method of Runtime class.
System.getRuntime().exec("notepad"); it is opening empty notepad.If i want to open a text file using this method how can i open.
For opening MSWord i have written like this.
System.getRuntime().exec(winword"); When i am using this, it's giving CreateProcess errorno = 193
Can any one help me in this
Thanks in advance
ramesh
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ramesh,
Below code solves ur problem.
Regards,
srini

*******************************************
Class: notepad.
Function: To open a file using java Runtime class using notpad.
Written by: S.K.Srinivasan
Email: srinivas_an@yahoo.com.
*******************************************
class notepad
{
public static void main (String args[]) throws Exception
{

(Runtime.getRuntime()).exec ("notepad c:\\ramesh.doc");
}
}
 
SRINI VASAN
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai buddy,
dunno.. i have fnished the word problem too...

Regards,
srini

*******************************************
Class: WINWORD
Function: To open a file using java Runtime class using Winword.
Written by: S.K.Srinivasan
Email: srinivas_an@yahoo.com.
*******************************************
class winword
{
public static void main (String args[]) throws Exception
{
String s []= new String[1] ;
s[0]="PATH=c:\\Program Files\\Microsoft Office\\Office";
(Runtime.getRuntime()).exec ("winword",s);
}
}
 
Ramesh Rao
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi srinivasan
Thank u for helping in my problem.i have tried u r code with notepad it is working ok with text files.
But when i have tried for opening word file, during execution it is giving "CreateProcess: winword error=2" ; error.
Kindly look in to this code, and suggest me.
for reference i am giving my code
String s[] = new String[1];
s[0] = "C:\\abc.doc";
(Runtime.getRuntime()).exec("winword", s);
Thank u
ramesh
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
There is a very good article about this at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
It helped me a lot.
/Malin

Originally posted by Ramesh Rao:
hi srinivasan
Thank u for helping in my problem.i have tried u r code with notepad it is working ok with text files.
But when i have tried for opening word file, during execution it is giving "CreateProcess: winword error=2" ; error.
Kindly look in to this code, and suggest me.
for reference i am giving my code
String s[] = new String[1];
s[0] = "C:\\abc.doc";
(Runtime.getRuntime()).exec("winword", s);
Thank u
ramesh


 
Did you just should on me? You should read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic