gpt4 book ai didi

Java Apache IOUtils : how to delete a file after read it into a byte array?

转载 作者:行者123 更新时间:2023-12-01 12:24:20 25 4
gpt4 key购买 nike

所以我尝试使用apache公共(public)库将文件读入字节数组,然后删除文件本身。但我做不到。有人可以告诉我为什么吗?

  File   aFile = new File("path_To_A_PDF_File");
byte[] fileBytes = IOUtils.toByteArray(new FileInputStream(aFile));
boolean result = aFile.delete();

System.out.println("is file " + aFile.getAbsolutePath() + " deleted? " + result);

如何删除该文件?谢谢

最佳答案

您必须关闭通过以下方式打开的流:new FileInputStream(aFile)

关于Java Apache IOUtils : how to delete a file after read it into a byte array?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26469356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com