请问我这段程序哪儿出错了?为什么不显示结果,字符串s和“error”都不打印出来:import java.io.IOException;
import java.io.*;public class compile {
public static void main(String[] args){
try {
InputStream p = Runtime.getRuntime().exec("ipconfig /all").getInputStream();
String s = (new BufferedReader(new InputStreamReader(p))).readLine();
if(s!=null)System.out.println(s);
else System.out.println("error");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.*;public class compile {
public static void main(String[] args){
try {
InputStream p = Runtime.getRuntime().exec("ipconfig /all").getInputStream();
String s = (new BufferedReader(new InputStreamReader(p))).readLine();
if(s!=null)System.out.println(s);
else System.out.println("error");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
InputStream p = Runtime.getRuntime().exec("cmd /c ipconfig /all").getInputStream();
第一行本来就是空行
import java.io.*; public class compile {
public static void main(String[] args){
try {
InputStream p = Runtime.getRuntime().exec("cmd /c ipconfig -all").getInputStream();
BufferedReader b = new BufferedReader(new InputStreamReader(p));
String s = "";
while( (s = b.readLine()) != null)
{
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}