try {
Process process = Runtime.getRuntime().exec("ping 10.144.98.100"); //调用Ping命令
}catch (Exception e)
{
e.printStackTrace();
}
Process process = Runtime.getRuntime().exec("ping 10.144.98.100"); //调用Ping命令
}catch (Exception e)
{
e.printStackTrace();
}
代码如下:
public class ping { public static void main(String[] args) {
byte[] pings = new byte[1024*16];
try {
Process process = Runtime.getRuntime().exec("ping 127.0.0.1"); //!)用Ping命令
InputStream in = process.getInputStream();
in.read(pings);
String tmp = new String(pings);
tmp = tmp.replaceAll("\r\r\n","");
System.out.println(tmp);
}catch (Exception e){
e.printStackTrace();
}
}
}
我用eclipse在windows下调试,信息输出不完全,而且会自动关闭eclipse。直接在liunx下编译的话也会出现信息输出不完全的情况,这是怎么回事啊?
InputStream in = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String s;
while ((s = br.readLine())!=null)
System.out.println(s);
还有个问题顺路问一下,用哪个包可以把文件压缩成tar.gz?