拿去试一试:import java.io.*;public class RunPing {
public static void main(String[] args) {
Process process;
try {
process = Runtime.getRuntime().exec("ping 127.0.0.1");
InputStream in = process.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
in.close();
reader.close();
process.destroy();
} catch(Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Process process;
try {
process = Runtime.getRuntime().exec("ping 127.0.0.1");
InputStream in = process.getInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
in.close();
reader.close();
process.destroy();
} catch(Exception e) {
e.printStackTrace();
}
}
}
解决方案 »
- 有用win7+sql2000sp4的吗?sql2000连接JDBC有问题
- 编译总提示未覆盖抽象方法KeyReleased
- 程序结果与我预想的不一样.....请教
- jni 调 dll问题
- 昨天一外企的面试题目
- java 可以打包吗?怎么打包?
- 怎么编译一个文件下面所有的java源文件,包括子文件夹中的哟
- 在<textarea>中输入的字符串 getString 是有换行符的,但用sendmail发送这个getString 后,在邮件中显示的这个字符串里的所有换行符全不
- 关于编码方式的问题?
- 关于Java的返回值问题:太奇怪了!!!
- 怎样解决JButton上中文是方框的问题????????
- 请问哪个方法可以得到刚刚executeUpdate(sql)中操作的行的编号???
import java.io.*;
import java.util.*;class IoRedirect {
public static void main(String Argv[]) {
try {
String[] command = {"/bin/sh", "-c", "/bin/ls > out.dat"};
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
System.out.println("return code: " + p.exitValue());
} catch (IOException e) {
System.err.println("IO error: " + e);
} catch (InterruptedException e1) {
System.err.println("Exception: " + e1.getMessage());
}
}
}