Runtime class in java

后端 未结 6 963
野性不改
野性不改 2020-12-18 12:03

How to execute a java program with the help of Runtime.getRuntime().exec(). For example we shall have the java file path as c:/java/abc.java. Please help me with the code.

6条回答
  •  萌比男神i
    2020-12-18 12:29

    Please see the excellent resource which used to be called javaalmanac.

    http://www.exampledepot.com/egs/java.lang/Exec.html

    try {
        // Execute a command with an argument that contains a space
        String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
        commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
        Process child = Runtime.getRuntime().exec(commands);
     } catch (IOException e) {
     }
    

提交回复
热议问题