Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Executing a file

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Executing a file

    I have a file "test.File". I want to use java to run that file with a program eg. Paint.NET. How can I do that?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Executing a file

    What does "run that file" mean?
    Are you asking how to ask the OS to start a program when it is given a file to be opened?
    See the Desktop class.

    Or if you have the full commandline to execute, see the Runtime class.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Executing a file

    I'm how to programatically execute test.File with Paint.NET (equallent of right clicking test.File, clicking "open with", then selecting Paint.NET)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Executing a file

    If you want to specify the command to use to open the file,
    build a commandline and use the Runtime exec() method to execute it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Executing a file

    and what command should i pass in the Runtime.exec() method??

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Executing a file

    The command that you want to execute.
    If you don't know the command, you should use the Desktop class.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. String if-else not executing
    By jimlumar` in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 13th, 2012, 09:51 AM
  2. Program not executing correctly
    By daemonlies in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 1st, 2012, 11:14 PM
  3. executing a process in backhand
    By jack_nutt in forum Java IDEs
    Replies: 1
    Last Post: November 9th, 2011, 08:58 PM
  4. Executing Oracle Procedure
    By java_mein in forum JDBC & Databases
    Replies: 0
    Last Post: May 14th, 2010, 02:41 PM
  5. Help Executing C Program From Java! (Ubuntu)
    By penguinGirl in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 18th, 2010, 01:47 PM