把時(shí)間設(shè)置,存到配置文件,Java程序去讀取就可以實(shí)現(xiàn);
創(chuàng)新互聯(lián)主要從事成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)城關(guān),10年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575
參考:
public class shutdownSystem extends Thread{
//設(shè)置關(guān)機(jī)時(shí)與分
private static shutdownH=10;
private static shutdownM=10;
public void run(){
// 獲取當(dāng)關(guān)時(shí)與分
int thisH=Calendar .HOUR_OF_DAY;
int thisM=Calendar.MINUTE;
if(shutdownH==thisH shutdownM==thisM){
try {
//關(guān)機(jī)
java.lang.Runtime.getRuntime().exec( "shutdown -s ");
} catch (java.io.IOException e) {
e.printStackTrace();
}finally{
try{
//間隔一分鐘檢查一次,確保能檢查到關(guān)機(jī)時(shí)間
this.sleep(60000);
}chatch(Exception ex){}
}
}
}
}
public class RuntimeTest {
public static void main(String[] args)
{
Runtime rt=Runtime.getRuntime();
try
{
rt.exec("shutdown.exe -s -t 40");
/*40的單位為秒,可以改成你想要的任何數(shù)字。
如果是想定時(shí)關(guān)機(jī),可用這句:rt.exec("at 19:00 shutdown.exe -s");19:00可以換成你想要的時(shí)間*/
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
必須有root權(quán)限的才可以,有的話執(zhí)行命令行就可以了 RuntimegetRuntime()exec(new String[]{ "su", "-c", "poweroff -f" }); RuntimegetRuntime()exec(new String[]{ "su", "-c", "reboot" });android完整的java關(guān)機(jī)代碼?
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("關(guān)機(jī)");
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("關(guān)機(jī)");
}
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("錯(cuò)誤指令!");
e1.printStackTrace();
}
}
}
}
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){}
}
}
上面這個(gè)程序?qū)崿F(xiàn)你所說的定時(shí)10秒關(guān)機(jī)
至于定時(shí)開機(jī)...你告訴我怎么在關(guān)機(jī)的狀態(tài)下執(zhí)行我的程序,我就把開機(jī)的程序給你寫出來.
網(wǎng)頁標(biāo)題:java立即關(guān)機(jī)代碼,java定時(shí)關(guān)機(jī)代碼
當(dāng)前URL:http://sd-ha.com/article44/dsecche.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、動(dòng)態(tài)網(wǎng)站、電子商務(wù)、建站公司、品牌網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)