mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix listFileNames bug
This commit is contained in:
@@ -342,7 +342,8 @@ public class FileUtil {
|
||||
JarFile jarFile = null;
|
||||
try {
|
||||
jarFile = new JarFile(path.substring(0, index));
|
||||
return ZipUtil.listFileNames(jarFile, path.substring(index + 1));
|
||||
// 防止出现jar!/cn/hutool/这类路径导致文件找不到
|
||||
return ZipUtil.listFileNames(jarFile, StrUtil.removePrefix(path.substring(index + 1), "/"));
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(StrUtil.format("Can not read file path of [{}]", path), e);
|
||||
} finally {
|
||||
|
@@ -1,5 +1,11 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FastByteArrayOutputStream;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -24,12 +30,6 @@ import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FastByteArrayOutputStream;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
||||
/**
|
||||
* 压缩工具类
|
||||
*
|
||||
@@ -828,7 +828,7 @@ public class ZipUtil {
|
||||
* 获取Zip文件中指定目录下的所有文件,只显示文件,不显示目录
|
||||
*
|
||||
* @param zipFile Zip文件
|
||||
* @param dir 目录前缀
|
||||
* @param dir 目录前缀(目录前缀不包含开头的/)
|
||||
* @return 文件列表
|
||||
* @since 4.6.6
|
||||
*/
|
||||
|
@@ -229,6 +229,15 @@ public class FileUtilTest {
|
||||
names = FileUtil.listFileNames(".");
|
||||
Assert.assertTrue(names.contains("hutool.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void listFileNamesInJarTest() {
|
||||
List<String> names = FileUtil.listFileNames("d:/test/hutool-core-5.1.0.jar!/cn/hutool/core/util ");
|
||||
for (String name : names) {
|
||||
Console.log(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
|
Reference in New Issue
Block a user