Skip to content

Instantly share code, notes, and snippets.

@qlong8807
Created October 25, 2019 07:26
Show Gist options
  • Save qlong8807/d084afbdfa71b196ed45dba1c58b7814 to your computer and use it in GitHub Desktop.
Save qlong8807/d084afbdfa71b196ed45dba1c58b7814 to your computer and use it in GitHub Desktop.
循环遍历多级文件名、把文件添加到系统环境变量
//循环遍历多级文件名并打印
public static void getFile(File file){
if(file != null){
File[] f = file.listFiles();
if(f != null){
for (File value : f) {
getFile(value);
}
}else{
System.out.println(file);
}
}
}
private static Sigar initSigar() {
try {
//此处只为得到依赖库文件的目录,可根据实际项目自定义
String file = Paths.get(PathKit.getWebRootPath(), "files", "sigar",".sigar_shellrc").toString();
File classPath = new File(file).getParentFile();
String path = System.getProperty("java.library.path");
String sigarLibPath = classPath.getCanonicalPath();
//为防止java.library.path重复加,此处判断了一下
if (!path.contains(sigarLibPath)) {
if (isOSWin()) {
path += ";" + sigarLibPath;
} else {
path += ":" + sigarLibPath;
}
System.setProperty("java.library.path", path);
}
return new Sigar();
} catch (Exception e) {
return null;
}
}
public static boolean isOSWin(){//OS 版本判断
String OS = System.getProperty("os.name").toLowerCase();
return OS.contains("win");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment