Java具有使用Runtime.exec对本地程序调用进行重定向的能力
如
以下是一个简单类的范例,展示了在Unix下运行ls命令的情形:import java.io.BufferedInputStream;
import java.io.IOException;public class ExecLs { static public void main(String[] args) {
String cmd = "ls" try {
Process ps = Runtime.getRuntime().exec(cmds);
System.out.print(loadStream(ps.getInputStream()));
System.err.print(loadStream(ps.getErrorStream()));
} catch(IOException ioe) {
ioe.printStackTrace();
}
}http://www.zdnet.com.cn/developer/code/story/0,2000081534,39102709,00.htm
如
以下是一个简单类的范例,展示了在Unix下运行ls命令的情形:import java.io.BufferedInputStream;
import java.io.IOException;public class ExecLs { static public void main(String[] args) {
String cmd = "ls" try {
Process ps = Runtime.getRuntime().exec(cmds);
System.out.print(loadStream(ps.getInputStream()));
System.err.print(loadStream(ps.getErrorStream()));
} catch(IOException ioe) {
ioe.printStackTrace();
}
}http://www.zdnet.com.cn/developer/code/story/0,2000081534,39102709,00.htm
String classname = "com.project.SqlBean";
String methodname = "getCmd";
Class[] parameterTypes = {};//参数类数组
Object[] args = {};//调用方法的参数数组
Class classInst = Class.forName(classname);
Object obj = classInst.newInstance();
Method methodInst = classInst.getMethod(methodname, parameterTypes);methodInst.invoke(obj, args);//调用方法