mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
添加获取当前文件夹名称方法
This commit is contained in:
parent
f540888a4c
commit
e83dd64c74
@ -3578,4 +3578,20 @@ public class FileUtil {
|
||||
public static void tail(File file, Charset charset) {
|
||||
FileUtil.tail(file, charset, Tailer.CONSOLE_HANDLER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前文件夹, 不管是否在jar包中都会返回文件夹的路径
|
||||
* class在jar包中返回jar所在文件夹,class不在jar中返回文件夹目录
|
||||
*/
|
||||
public static String getCurrentDir(Class clazz) {
|
||||
String currentDir = null;
|
||||
File file = new File(clazz.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||
if (file.isFile()) {
|
||||
currentDir = file.getParentFile().getAbsolutePath();
|
||||
} else {
|
||||
currentDir = file.getAbsolutePath();
|
||||
}
|
||||
return currentDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user