Results 1 to 6 of 6
  1. #1
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default 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?

  2. #2
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    6

    Default

    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

  3. #3
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Nice mrmattt, I will have to remember that one.

  4. #4
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

    Default

    Sorry, I've never worked with Runtime class. Could you be more specific?

  5. #5
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    The string you pass into the method will be given to the OS to execute.

    so if you did something like
    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 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.

    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.

  6. #6
    StokedOnMe is offline Member
    Join Date
    Sep 2009
    Posts
    14
    Rep Power
    0

Similar Threads

  1. Read and Open *.txt Files? help!!
    By ashton in forum New To Java
    Replies: 9
    Last Post: 11-01-2009, 03:42 PM
  2. Different Files Open in File -> Open Workspace
    By mgm2010 in forum JCreator
    Replies: 0
    Last Post: 04-11-2009, 02:14 PM
  3. Deploying java applications.
    By J-Live in forum New To Java
    Replies: 7
    Last Post: 11-24-2008, 07:08 AM
  4. JDOM in java applications
    By boy22 in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2007, 05:38 PM
  5. convert VB6 applications to Java
    By bbq in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 03:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •