
正文
java操作关机代码 java自动关机代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java语言的自动关机的代码
public class RuntimeTest {
public static void main(String[] args)
{
Runtime rt=Runtime.getRuntime();
try
{
rt.exec("shutdown.exe -s -t 40");
/*40java操作关机代码的单位为秒java操作关机代码,可以改成你想要的任何数字。
如果是想定时关机java操作关机代码,可用这句:rt.exec("at 19:00 shutdown.exe -s");19:00可以换成你想要的时间*/
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
相关问答
Q1: 如何用Java编写一个定时开关机软件?(pc版)
定时开机是BIOS设置java操作关机代码的。
定时关机这个好写。。。。
启动时检测一次当前时间java操作关机代码,算出距离目标时间的值。
然后线程休眠这么长时间。
然后执行控制台命令,调用windows系统自带的关机命令就可以java操作关机代码了。
java调用控制台的关机命令如下
Runtime.getRuntime().exec("shutdown -s");
lang包下的,直接可以用~
系统是winXP+JVM1.5
Q2: 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秒关机
至于定时开机...你告诉我怎么在关机的状态下执行我的程序,我就把开机的程序给你写出来.
Q3: JAVA语句怎么实现让电脑定时开机和定时关机?
要实现电脑的定时开机功能,首先应确定电脑使用的电源是ATX电源,而且主板支持时钟唤醒功能,而且操作系统是Windows 98或以上版本的操作系统,然后在开机时进入BIOS设置,选择“Power Management Setup”项后,将“Resume By Alarm”项设为打开状态,即设置为“Enabled”。然后在时间设定中的“Data”项中选0,在“Time”中设定定时开机的时间,设置好后按【F10】键保存退出,即可实现电脑定时开机功能。需注意的是不要将电脑的电源插头拨了。
定时关机:首先在“开始”菜单点击“运行”,输入“at xx:xx shoutdown -s” 可以实现定时关机,xx:xx指的是具体关机时间。还可以输入“shoutdown.exe -s -t xxxx”。xxxx指的是欲多久后关机的秒数。如果运行程序后想取消,则输入“shutdown -a”即可(注意以上输入时不包括引号)。本人在上网的时候运用了此招,就再也没发生上网失控的现象了。 如果要在Windows 2000下运行的话,只需将Windows XP c:\windows\system32目录下的“shutdown.exe”文件拷贝到Windows 2000下的c:\winnt\system32目录下即可。
Q4: java如何实现一个到特定时间自动关机?
把时间设置,存到配置文件,Java程序去读取就可以实现;
参考:
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){}
}
}
}
}
Q5: 如何用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操作关机代码和java自动关机代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







