This commit is contained in:
Looly 2019-09-16 19:00:11 +08:00
parent acb54849dd
commit 0fbede424e

View File

@ -55,6 +55,7 @@ import cn.hutool.core.io.file.LineSeparator;
import cn.hutool.core.io.file.Tailer; import cn.hutool.core.io.file.Tailer;
import cn.hutool.core.io.resource.ResourceUtil; import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharUtil; import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
@ -313,30 +314,29 @@ public class FileUtil {
int index = path.lastIndexOf(FileUtil.JAR_PATH_EXT); int index = path.lastIndexOf(FileUtil.JAR_PATH_EXT);
if (index < 0) { if (index < 0) {
// 普通目录 // 普通目录
final List<String> paths = new ArrayList<String>(); final List<String> paths = new ArrayList<>();
final File[] files = ls(path); final File[] files = ls(path);
for (File file : files) { for (File file : files) {
if (file.isFile()) { if (file.isFile()) {
paths.add(file.getName()); paths.add(file.getName());
} }
} }
} else { return paths;
// jar文件 }
path = getAbsolutePath(path);
// jar文件中的路径 // jar文件
index = index + FileUtil.JAR_FILE_EXT.length(); path = getAbsolutePath(path);
JarFile jarFile = null; // jar文件中的路径
try { index = index + FileUtil.JAR_FILE_EXT.length();
jarFile = new JarFile(path.substring(0, index)); JarFile jarFile = null;
return ZipUtil.listFileNames(jarFile, path.substring(index + 1)); try {
} catch (IOException e) { jarFile = new JarFile(path.substring(0, index));
throw new IORuntimeException(StrUtil.format("Can not read file path of [{}]", path), e); return ZipUtil.listFileNames(jarFile, path.substring(index + 1));
} finally { } catch (IOException e) {
IoUtil.close(jarFile); throw new IORuntimeException(StrUtil.format("Can not read file path of [{}]", path), e);
} } finally {
IoUtil.close(jarFile);
} }
return new ArrayList<>(0);
} }
/** /**
@ -357,8 +357,8 @@ public class FileUtil {
* @return File * @return File
*/ */
public static File file(String path) { public static File file(String path) {
if (StrUtil.isBlank(path)) { if (null == path) {
throw new NullPointerException("File path is blank!"); return null;
} }
return new File(getAbsolutePath(path)); return new File(getAbsolutePath(path));
} }
@ -1765,7 +1765,7 @@ public class FileUtil {
*/ */
public static String getName(String filePath) { public static String getName(String filePath) {
if (null == filePath) { if (null == filePath) {
return filePath; return null;
} }
int len = filePath.length(); int len = filePath.length();
if (0 == len) { if (0 == len) {