mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
回退 'Pull Request !106 : 添加获取class当前文件夹名称方法'
This commit is contained in:
parent
135b172653
commit
65f121585d
@ -3578,21 +3578,4 @@ public class FileUtil {
|
||||
public static void tail(File file, Charset charset) {
|
||||
FileUtil.tail(file, charset, Tailer.CONSOLE_HANDLER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取class类当前文件夹, 不管是否在jar包中都会返回文件夹的路径
|
||||
* class在jar包中返回jar所在文件夹,class不在jar中返回文件夹目录
|
||||
* jdk中的类不能使用此方法
|
||||
*/
|
||||
public static String getClassDir(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,31 +1,23 @@
|
||||
package cn.hutool.core.io.file;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TailerTest {
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
public class TailerTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tailTest() {
|
||||
FileUtil.tail(FileUtil.file("e:/tail.txt"), CharsetUtil.CHARSET_GBK);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tailWithLinesTest() {
|
||||
Tailer tailer = new Tailer(FileUtil.file("f:/test/test.log"), Tailer.CONSOLE_HANDLER, 2);
|
||||
tailer.start();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testDir() {
|
||||
System.out.println(FileUtil.getClassDir(FileUtil.class));
|
||||
System.out.println(FileUtil.getClassDir(Data.class));
|
||||
System.out.println(FileUtil.getClassDir(Test.class));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user