And this is achieved by a class named ProcessBuilder ,
All processes are represented Process class and ProcessBuilder offers more control more over the processes.
ProcessBuilder defines three constructors.
ProcessBuilder(List<String> args)
ProcessBuilder(String.....arg)
Here args are list of arguments that specify the name of the progrm to be executed along with any reqired command line arguments.
Now lets see an example which open notepad..
class ProcessDemo{
public static void main(String[] jfb){
try{
ProcessBuilder proc=new ProcessBuilder("notepad.exe","JBFB");
proc.start();
}catch(Exception hj){
System.out.println("Error not der"+hj);
}
}
}
To compile it in Eclipse IDE see here
I guess no need of explaining it is very simple..You can try few more editors or other applications to open with java program.
nice
ReplyDeleteThis is working
ReplyDeleteit very help for me
ReplyDeletethanks u very much
venigalla.srikanth@gmail.com