Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

读取文件超过3GB时报java.lang.NegativeArraySizeException: -221445712 #3577

Closed
zhiyuFeng opened this issue May 8, 2024 · 1 comment
Labels

Comments

@zhiyuFeng
Copy link

版本情况

JDK版本: openjdk_11.0.16
hutool版本: 5.8.27(请确保最新尝试是否还有问题)

问题描述(包括截图)

  1. 复现代码
public static void main(String[] args) {
        String read = IoUtil.read(FileUtil.getInputStream("data.json"), StandardCharsets.UTF_8);
    }
  1. 堆栈信息
Exception in thread "main" java.lang.NegativeArraySizeException: -221445712
	at cn.hutool.core.io.FastByteBuffer.toArray(FastByteBuffer.java:210)
	at cn.hutool.core.io.FastByteArrayOutputStream.toByteArray(FastByteArrayOutputStream.java:93)
	at cn.hutool.core.io.IoUtil.readBytes(IoUtil.java:491)
	at cn.hutool.core.io.IoUtil.readBytes(IoUtil.java:457)
	at cn.hutool.core.io.IoUtil.read(IoUtil.java:368)
  1. 测试涉及到的文件(注意脱密)

比如报错的Excel文件,有问题的图片等。

@looly
Copy link
Member

looly commented May 9, 2024

你这个文件太大了,不能一次性读取(超过了byte[]最大容量)

见:https://stackoverflow.com/questions/816142/strings-maximum-length-in-java-calling-length-method

考虑其它读取方式。

@looly looly closed this as completed May 9, 2024
@looly looly added the question label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants