原理说明
相当于 Win+R ,然后输入相应命令,例:
定时关机
public class ShutDown {
public static void main(String[] args) throws IOException {
//键盘输入
Scanner sc = new Scanner(System.in);
//提示输入数字表示倒计时
System.out.print("请输入关机倒计时:");
//输入倒计时/秒
int time = sc.nextInt();
// 定时关机,单位秒
//Runtime.getRuntime().exec("shutdown -s -t 1000");
//在某个时间点关机
//Runtime.getRuntime().exec("at 24:00 shutdown -s");
// 用户输入时间
Runtime.getRuntime().exec("shutdown -s -t "+time);
//每隔一秒输出一次倒计时
for(int i=time;i>=0;i--) {
try {
//沉睡一秒
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("倒计时"+i+"秒关机");
}
}
}
取消关机
public class ShutDown {
public static void main(String[] args) throws IOException {
//在已经存在关机计划的情况下执行,取消关机计划
Runtime.getRuntime().exec("shutdown -a");
}
}
参数说明
命令 | 含义 |
---|---|
shutdown | 执行 Shutdown.exe 程序 |
shutdown -s | 关闭、关机 |
shutdown -s -t | 后面接数字,表示倒计时多少秒后关机 |
shutdown -f | 强制正在运行的应用程序关闭而不事先警告用户 |
shutdown -m \计算机名 | 控制远程计算机 |
shutdown -i | 显示“远程关机”图形用户界面,但必须是Shutdown的第一个参数 |
shutdown -l | 注销当前用户 |
shutdown -r | 重启 |
shutdown -h | 休眠 |
at 23:00 shutdown -s | 定时 23:00 关机 |
导出可运行的 jar 文件
Eclipse
点击菜单栏文件 ——》Export ——》java ——》JAR File ——》选择相应包下的相应java文件 ——》Browse选择保存路径并命名 ——》next、next ——》Browse选择需要运行的文件 ——》Finish
IDEA
点击菜单栏文件 ——》项目结构 ——》Artifacts ——》+ ——》JAR ——》From modules with dependencies… ——》Main class 选择需要运行的java类 ——》 确定、应用、确定 ——》菜单栏构建 ——》Build artifacts… ——》build,然后就会新增一个目录(包含jar文件)(复制到桌面双击执行即可)
一文一哲理
生活五味杂陈,人生纷纷扰扰