通过Runtime.getRumtime().exec()方法打开IE,网页为www.google.com,命令在cmd中已经试过没问题
import java.io.*;public class Test
{
public static void main(String[] args) throws Exception
{
Process p = Runtime.getRuntime().exec(new String[]{"iexplore.exe www.google.com"}, null, new File("C:/Program Files/Internet Explorer"));
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String temp;
while((temp = br.readLine()) != null)
{
System.out.println(temp);
}
}
}
运行报错:
Exception in thread "main" java.io.IOException: Cannot run program "iexplore.exe
www.google.com" (in directory "C:\Program Files\Internet Explorer"): CreateProc
ess error=2, ?????????
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Test.main(Test.java:7)
Caused by: java.io.IOException: CreateProcess error=2, ?????????
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 3 more
import java.io.*;public class Test
{
public static void main(String[] args) throws Exception
{
Process p = Runtime.getRuntime().exec(new String[]{"iexplore.exe www.google.com"}, null, new File("C:/Program Files/Internet Explorer"));
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String temp;
while((temp = br.readLine()) != null)
{
System.out.println(temp);
}
}
}
运行报错:
Exception in thread "main" java.io.IOException: Cannot run program "iexplore.exe
www.google.com" (in directory "C:\Program Files\Internet Explorer"): CreateProc
ess error=2, ?????????
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Test.main(Test.java:7)
Caused by: java.io.IOException: CreateProcess error=2, ?????????
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 3 more
希望楼主问题解决了也通知声!
如果路径中有空格,必须用双引号括住