It's not a secret anymore!*
The moose likes Beginning Java and the fly likes How can one run a native application like notepad within a java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How can one run a native application like notepad within a java application" Watch "How can one run a native application like notepad within a java application" New topic
Author

How can one run a native application like notepad within a java application

Adeiza Yusuf
Greenhorn

Joined: Oct 06, 2010
Posts: 24
Please i just want to find out if its possible to run a native application like notepad from my java code.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can just invoke it with Runtime.exec() but before doing that read this article.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Adeiza Yusuf
Greenhorn

Joined: Oct 06, 2010
Posts: 24
thanks Wouter, i read the article about the flaws and i have even learnt a new way to do it without the flaws of the Runtime. i used the Desktop class instead. your answer lead me to knowing something new. I really appreciate it.


this is what i have used.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

That's a very good solution for opening files (with their preferred application). For running applications / commands java.lang.Process (through ProcessBuilder or Runtime.exec) is still the way to go.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I like Adeiza's solution, because it will use the user's preferred text editor, which isn't necessarily Notepad.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Kr Manish
Ranch Hand

Joined: Jul 30, 2010
Posts: 138
java.lang.Process is much more general and not specialized like the Desktop class. So depends. OP asked for an application though.


You know what I am saying ?
 
wood burning stoves
 
subject: How can one run a native application like notepad within a java application
 
Similar Threads
Any Solution for this.
java lang NoClassDefFoundError with SWT Class
Process... How in depth can I control it ?
r.exec("javac","source.java);
Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp. Please help basic issue