`
junge8618
  • 浏览: 121070 次
  • 性别: Icon_minigender_1
  • 来自: 邵阳
社区版块
存档分类
最新评论

Java特需的应用

阅读更多
1.在Java中调用操作系统的命令(或者脚本)
String commandLine = "HELP";
Runtime runtime = Runtime.getRuntime();

try {
Process process = runtime.exec(commandLine);
//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();
}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics