Results 1 to 6 of 6
- 09-03-2009, 10:58 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 14
- Rep Power
- 0
Using Java to open applications and files
I recently wrote a program that allows me to search my files in a very specific way. They are all Guitar Pro files (.gp3, .gp4, .gp5) if it makes any difference for anybody. In the end, it prints out the list of files you search for.
Is there a way to make the file open in the application associated with the extension (Guitar Pro)? So, can Java do an equivalent of double-clicking the file or, maybe, open the application and then open the file itself?
- 09-03-2009, 11:07 PM #2
Yes, you can push it to your OS and have it open with the default app. You might have some issues with linux depending on the file, but in windows it should work fine:
try something like this:
Java Code:Runtime.getRuntime().exec(...);
My Hobby Project: LegacyClone
- 09-04-2009, 12:08 AM #3
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
Nice mrmattt, I will have to remember that one.
- 09-04-2009, 12:08 AM #4
Member
- Join Date
- Sep 2009
- Posts
- 14
- Rep Power
- 0
Sorry, I've never worked with Runtime class. Could you be more specific?
- 09-04-2009, 12:16 AM #5
The string you pass into the method will be given to the OS to execute.
so if you did something like
If your operating system isn't configured to figure out to do with the file type .gpx then you are going to need to figure out how you can pass it to the binary as a command line argument.Java Code:Runtime.getRuntime.exec( "gedit \"file.txt\"" ); // Open file.txt with gedit Runtime.getRuntime.exec( "notepad \"file.txt\"" ); // Open file.txt with notepad
If you haven't used the Runtime class, then check out the documentation for it. It has a full description on the exec(String command) method.Last edited by Mr.Beans; 09-04-2009 at 12:21 AM.
- 09-04-2009, 01:34 AM #6
Member
- Join Date
- Sep 2009
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
Read and Open *.txt Files? help!!
By ashton in forum New To JavaReplies: 9Last Post: 11-01-2009, 03:42 PM -
Different Files Open in File -> Open Workspace
By mgm2010 in forum JCreatorReplies: 0Last Post: 04-11-2009, 02:14 PM -
Deploying java applications.
By J-Live in forum New To JavaReplies: 7Last Post: 11-24-2008, 07:08 AM -
JDOM in java applications
By boy22 in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 05:38 PM -
convert VB6 applications to Java
By bbq in forum New To JavaReplies: 1Last Post: 07-05-2007, 03:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks