mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix listFileNames bug
This commit is contained in:
parent
067c0578d6
commit
21881a1609
@ -20,6 +20,7 @@
|
||||
### Bug修复
|
||||
* 【core 】 修复NumberUtil.mul中null的结果错误问题(issue#I17Y4J@Gitee)
|
||||
* 【core 】 修复当金额大于等于1亿时,转换会多出一个万字的bug(pr#715@Github)
|
||||
* 【core 】 修复FileUtil.listFileNames位于jar内导致的文件找不到问题(issue#listFileNames@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user