我正在嘗試設定一個程式以在啟動后自動重新啟動 Windows,并增加已完成的重新啟動次數。
我已經撰寫了少量代碼,但是當放置在啟動檔案夾中時,它甚至沒有重新啟動系統本身。您可以非常簡短地看到命令提示符,然后什么也沒有發生。
import java.awt.event.WindowEvent;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.io.*;
import javax.swing.*;
public class AutoRestart {
public static void main(String[] args) throws IOException {
int numRestarts = 0;
Runtime r = Runtime.getRuntime();
numRestarts ;
File outFile = new File("C:\\reboots\\numberOfReboots.txt");
if (outFile.exists()) {
System.exit(0);
}
PrintWriter writer = new PrintWriter(outFile);
writer.println("Number of times rebooted: " numRestarts);
writer.close();
r.exec("shutdown -r -t 0");
System.out.println("Restarting. . .");
}
}
uj5u.com熱心網友回復:
int 變數不會在重新啟動后繼續存在,您可以嘗試從您剛剛創建的檔案中讀取并增加其中的數字。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/345315.html
上一篇:Thymeleaf中未識別的屬性
