linux Runtime

来源:互联网 发布:js 隐藏鼠标 编辑:程序博客网 时间:2024/05/22 11:50

Runtime.getRuntime().exec("main.exe "你的字符"")

------------------------------------------------------------------------

Runtime   runtime   =   new   Runtime();   
  String   fileName   =   "c:\\test.txt";   
  String   commandStr   =   "rundll32   url.dll,FileProtocolHandler   "+fileName;   
  runtime.exe(commandStr   );   
  或者   
  Runtime   runtime   =   new   Runtime();   
  String   fileName   =   "c:\\test.txt";   
  String   commandStr   =   "notePad   "+fileName;   
  runtime.exe(commandStr   );   
Runtime.getRuntime().exec("test.exe   "+param1+"   "+param2+"   "+param3);



Runtime.getRuntime().exec("c:\\windows\\system32\\cmd echo abc");


public class transferExe {

    /**

     * @param args

     */

    public static void main(String[] args) {

       openWinExe();

       openMyExe();

    }

 

    // 用Java调用windows系统的exe文件,比如notepad,calc之类

    public static void openWinExe() {

       Runtime rn = Runtime.getRuntime();

       Process p = null;

       try {

           String command = "notepad";

           p = rn.exec(command);

       } catch (Exception e) {

           System.out.println("Error win exec ");

       }

    }

 

    // 2.0调用其他的可执行文件,例如:自己制作的exe,或是下载安装的软件

    public static void openMyExe() {

       Runtime rn = Runtime.getRuntime();

       Process p = null;

       try {

           p = rn.exec("\"E:/QQ2008Spring.exe\"");

       } catch (Exception e) {

           System.out.println("Error my exec ");

       }

    }

}

 


在Java程序中获取当前运行程序的路径

import java.io.*;

public class Test {

       public static void main(String[] args) {

              File directory  = new File(".");

              try {

                     File newPath = new File(directory.getCanonicalPath()+"NewFolder");

                     newPath.mkdir();

              }catch(Exception exp)

              {

                     exp.printStackTrace();

              }

       }

}

//File directory       = new File(".");

//directory.getCanonicalPath();取得当前路径




String[]   open={"NotePad.exe","C:\\1.txt"};   
  Runtime.getRuntime().exec(open);



  Runtime   rt=Runtime.getRuntimee();   
  rt.exec("C:\\Program   Files\\Accessories\\Wordpad   D:\\xxxx.txt");
Top