怎么用exec来执行c:\a.exe? envp - array of strings, each element of which has environment variable settings in format name=value.就是环境变量,比如{"os=winnt", "user=someone"} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果不用设置环境变量呢,好像envp不能为空 exec(String command)就可以了,有适用各种参数的方法嘛 envp 可以为空String[] commands,里是命令和参数 example:import java.io.BufferedInputStream;import java.io.IOException;import java.io.InputStream;public class Command2{ public static void main(String[] args) { String cmd = "ping localhost"; try { Process ps = Runtime.getRuntime().exec(cmd); System.out.print(loadStream(ps.getInputStream())); System.err.print(loadStream(ps.getErrorStream())); } catch(IOException ioe) { ioe.printStackTrace(); } } // read an input-stream into a String private static String loadStream(InputStream is) throws IOException { int ptr = 0; BufferedInputStream bis = new BufferedInputStream(is); StringBuffer buffer = new StringBuffer(); while( (ptr = bis.read()) != -1 ) { buffer.append((char)ptr); } return buffer.toString(); }} 笨人新手求大神给我讲讲下面while循环,下面程序中的count为什么为3 线程同步的问题,急!!! 求救java swing做的记事本设置不了默认字体大小有时候退出还会报错 日期格式处理在不同操作系统下出现的诡异问题 写了一个UDP的聊天系统,但是无法实现广播,请各位帮忙看看 jdbc 数据库登录时出现问题了!! vector 怎么实现查找功能? JSP(SERVLET)是在客户端运行的,还是在服务器运行? 怎么不能给分??????奇了 请问如何在一个jar包中删除一些文件?比如jre中自带的rt.jar? 如何在java中访问注册表 Code too large问题
就可以了,有适用各种参数的方法嘛
String[] commands,里是命令和参数
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;public class Command2
{
public static void main(String[] args)
{
String cmd = "ping localhost";
try
{
Process ps = Runtime.getRuntime().exec(cmd);
System.out.print(loadStream(ps.getInputStream()));
System.err.print(loadStream(ps.getErrorStream()));
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
// read an input-stream into a String
private static String loadStream(InputStream is) throws IOException
{
int ptr = 0;
BufferedInputStream bis = new BufferedInputStream(is);
StringBuffer buffer = new StringBuffer();
while( (ptr = bis.read()) != -1 )
{
buffer.append((char)ptr);
}
return buffer.toString();
}
}