为什么要用java做不擅长的事呢?

解决方案 »

  1.   

    那怎么能实现啊?无论什么方法都可以。其实我觉得也是可以实现的。可是我不知道win2000的关机命令是什么。还有怎么调用这些命令。。一定是可行的。还请高手赐教
      

  2.   

    也许这个可以作参考,在命令行敲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();
        }
    }
      

  3.   

    只要这么一句就够了
     Process ps = Runtime.getRuntime().exec("shutdown -s");
    定时的话,加上一个另外的线称来控制获得本地时间,然后在规定的时间内执行
    Process ps = Runtime.getRuntime().exec("shutdown -s");