Running a .exe file using Java

前端 未结 4 1597
既然无缘
既然无缘 2020-12-06 15:45

How to run an exe file using java code?The .exe file is already there. The plan is to write a Java code for running the same. Any tutorial or reference for the same?

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 16:30

    Try the following code:

    try 
    {     
         Runtime rt = Runtime.getRuntime() ;     
         Process p = rt.exec("Program.exe") ;     
         InputStream in = p.getInputStream() ;    
         OutputStream out = p.getOutputStream ();     
         InputStream err = p.getErrorStream() ; 
    
         //do whatever you want 
    
         p.destroy() ; 
    } 
    catch(Exception exc) 
    {
     /*handle exception*/
    }
    

提交回复
热议问题