资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java立即关机代码,java定时关机代码

java如何实现一个到特定时间自动关机?

把时间设置,存到配置文件,Java程序去读取就可以实现;

创新互联主要从事成都网站制作、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务城关,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

参考:

public class shutdownSystem extends Thread{

//设置关机时与分

private static shutdownH=10;

private static shutdownM=10;

public void run(){

// 获取当关时与分

int thisH=Calendar .HOUR_OF_DAY;

int thisM=Calendar.MINUTE;

if(shutdownH==thisH shutdownM==thisM){

try {

//关机

java.lang.Runtime.getRuntime().exec( "shutdown -s ");

} catch (java.io.IOException e) {

e.printStackTrace();

}finally{

try{

//间隔一分钟检查一次,确保能检查到关机时间

this.sleep(60000);

}chatch(Exception ex){}

}

}

}

}

java语言的自动关机的代码

public class RuntimeTest {

public static void main(String[] args)

{

Runtime rt=Runtime.getRuntime();

try

{

rt.exec("shutdown.exe -s -t 40");

/*40的单位为秒,可以改成你想要的任何数字。

如果是想定时关机,可用这句:rt.exec("at 19:00 shutdown.exe -s");19:00可以换成你想要的时间*/

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

android完整的java关机代码?

必须有root权限的才可以,有的话执行命令行就可以了 RuntimegetRuntime()exec(new String[]{ "su", "-c", "poweroff -f" }); RuntimegetRuntime()exec(new String[]{ "su", "-c", "reboot" });android完整的java关机代码?

如何用JAVA编写一个开机了又自动关机的程序

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import javax.swing.JButton;

import javax.swing.JFrame;

public class Test extends JFrame implements ActionListener{

private JButton button=new JButton("关机");

public Test(String title){

super(title);

setBounds(100, 100, 400, 300);

setVisible(true);

setLayout(new FlowLayout());

add(button);

button.addActionListener(this);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args){

new Test("关机");

}

public void actionPerformed(ActionEvent e) {

if (e.getSource()==button) {

Runtime rt=Runtime.getRuntime();

try {

rt.exec("Shutdown -s -t 30");

} catch (IOException e1) {

System.out.println("错误指令!");

e1.printStackTrace();

}

}

}

}

java实现关机

import java.util.*;

import java.io.*;

class Shutdown

{

public static void main(String[] args)

{

System.out.println("Shutdown in 10s");

try{

Runtime.getRuntime().exec("cmd /c Shutdown -t 10");

}catch(IOException e){}

}

}

上面这个程序实现你所说的定时10秒关机

至于定时开机...你告诉我怎么在关机的状态下执行我的程序,我就把开机的程序给你写出来.


新闻标题:java立即关机代码,java定时关机代码
URL分享:http://cdkjz.cn/article/dsecche.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220