1.在Java中调用操作系统的命令(或者脚本)
String commandLine = "HELP";
[color=red]Runtime runtime = Runtime.getRuntime();[/color]
try {
[color=red]Process process = runtime.exec(commandLine);[/color]
//OutputStream outputstream = process.getOutputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder errorDesc = new StringBuilder();
for (String str = br.readLine(); str != null; str = br
.readLine())
{
errorDesc.append(str);
}
System.out.println(errorDesc.toString());
} catch (IOException e) {
e.printStackTrace();
}
2.计时器
public class MyTimer {
private Timer timer;
private static final int STOP_TIME = 3000;
private class SayHello extends TimerTask {
@Override
public void run() {
System.out.println("say hello " + new Date().toLocaleString());
}
}
public void start(){
if ( null == this.timer){
timer = new Timer("Say Hello");
}
SayHello sayHello = new SayHello();
timer.schedule(sayHello, 0, MyTimer.STOP_TIME);
}
public static void main(String[] args){
MyTimer myTimer = new MyTimer();
myTimer.start();
}
}
String commandLine = "HELP";
[color=red]Runtime runtime = Runtime.getRuntime();[/color]
try {
[color=red]Process process = runtime.exec(commandLine);[/color]
//OutputStream outputstream = process.getOutputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder errorDesc = new StringBuilder();
for (String str = br.readLine(); str != null; str = br
.readLine())
{
errorDesc.append(str);
}
System.out.println(errorDesc.toString());
} catch (IOException e) {
e.printStackTrace();
}
2.计时器
public class MyTimer {
private Timer timer;
private static final int STOP_TIME = 3000;
private class SayHello extends TimerTask {
@Override
public void run() {
System.out.println("say hello " + new Date().toLocaleString());
}
}
public void start(){
if ( null == this.timer){
timer = new Timer("Say Hello");
}
SayHello sayHello = new SayHello();
timer.schedule(sayHello, 0, MyTimer.STOP_TIME);
}
public static void main(String[] args){
MyTimer myTimer = new MyTimer();
myTimer.start();
}
}