aspose file tools*
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 Spring in Action this week in the Spring 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: 19720
    
  20

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: 14269
    
  21

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 8 API documentation
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