-6

How can I run a file (like an exe program) using java? I have searched up how to open a file (even on oracle docs) to no avail. Is there a class to help me with this? I tried

try 
{     
Runtime rt = Runtime.getRuntime() ;     
Process p => rt.exec("Program.exe") ;     
InputStream in = p.getInputStream() ;    
 OutputStream out = p.getOutputStream ();     
 InputSream err = p.getErrorStream() ; 


p.destroy() ; 
} 
catch(Exception exc) 
{
}

But it didn't work

Joao
  • 23
  • 10
  • 3
    really ? took like 20 seconds tops to find a relevant tutorial on google – njzk2 Nov 20 '13 at 22:37
  • 1
    A good place to start would be [`ProcessBuilder`](http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html) – MadProgrammer Nov 20 '13 at 22:39
  • 1
    See the answers to this question http://stackoverflow.com/questions/10685893/run-exe-file-from-java-from-file-location – Mike Clark Nov 20 '13 at 22:40
  • 1
    @Joao _Should I switch to google?_ depends on your preference. Different search engines use different algorithms, indexing... etc for search. – Smit Nov 20 '13 at 22:43

1 Answers1

1

Try this

Runtime.getRuntime().exec("c:\\program files\\test\\test.exe", null, new File("c:\\program files\\test\\"));
Antp
  • 255
  • 1
  • 4
  • 12