SystemUtil.java
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cn.csbr.app.util;
import cn.hutool.core.io.FileUtil;
import lombok.AllArgsConstructor;
import java.io.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
public class SystemUtil {
public static void restartMain() {
File[] files = FileUtil.ls(System.getProperty("user.dir"));
HashMap<Long, String> fileMap = new HashMap<>();
for (File file : files) {
if (file.getName().endsWith(".jar")) {
fileMap.put(file.lastModified(), file.getName());
}
}
Set<Long> longs = fileMap.keySet();
Long max = Collections.max(longs);
System.out.println(fileMap.get(max));
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", "java", "-jar", fileMap.get(max));
new start(pb).start();
new exit().start();
}
public static void ReHcg(){
// String path = "D:\\public.bat";
Runtime run = Runtime.getRuntime();
try {
run.exec("cmd /k shutdown -r -t 2");
} catch (Exception e) {
e.printStackTrace();
}
}
}
@AllArgsConstructor
class start extends Thread {
ProcessBuilder pb;
@Override
public void run() {
try {
pb.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class exit extends Thread {
@Override
public void run() {
System.exit(0);
}
}