用java实现定时关机?? 为什么要用java做不擅长的事呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那怎么能实现啊?无论什么方法都可以。其实我觉得也是可以实现的。可是我不知道win2000的关机命令是什么。还有怎么调用这些命令。。一定是可行的。还请高手赐教 也许这个可以作参考,在命令行敲shutdown -a取消关机,敲shutdown获取更多帮助。import java.io.*;public class ExecShutdown { static public void main(String[] args) { String cmd[] = {"shutdown","-s"}; try { Process ps = Runtime.getRuntime().exec(cmd); System.out.print(loadStream(ps.getInputStream())); System.err.print(loadStream(ps.getErrorStream())); } catch(IOException ioe) { ioe.printStackTrace(); } } static String loadStream(InputStream in) throws IOException { int ptr = 0; in = new BufferedInputStream(in); StringBuffer buffer = new StringBuffer(); while( (ptr = in.read()) != -1 ) { buffer.append((char)ptr); } return buffer.toString(); }} 只要这么一句就够了 Process ps = Runtime.getRuntime().exec("shutdown -s");定时的话,加上一个另外的线称来控制获得本地时间,然后在规定的时间内执行Process ps = Runtime.getRuntime().exec("shutdown -s"); 大师们!我又来了。。 scjp考证试题 java数据库大量添加数据性能问题 一道面试题,前辈帮下忙! 关于构造方法 一个非常简单地关于String的问题,高手都来看看 Java堆栈问题 请教一个小问题 多线程下 共享使用 CONNECTION, 可能存在互斥问题吗? xstream,xml解析问题 如何杀死进程,请指教! 求救关于JFrame中不能输出界面的问题。
static public void main(String[] args) {
String cmd[] = {"shutdown","-s"};
try {
Process ps = Runtime.getRuntime().exec(cmd);
System.out.print(loadStream(ps.getInputStream()));
System.err.print(loadStream(ps.getErrorStream()));
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
static String loadStream(InputStream in) throws IOException {
int ptr = 0;
in = new BufferedInputStream(in);
StringBuffer buffer = new StringBuffer();
while( (ptr = in.read()) != -1 ) {
buffer.append((char)ptr);
}
return buffer.toString();
}
}
Process ps = Runtime.getRuntime().exec("shutdown -s");
定时的话,加上一个另外的线称来控制获得本地时间,然后在规定的时间内执行
Process ps = Runtime.getRuntime().exec("shutdown -s");