最近在使用word模板生成pdf,一开始由于一些流没有关闭,导致内存溢出,出现"too many open files",后来就对代码中流和读写对象一通关闭。

代码调整之后,本以为可以完美的解决问题,结果又出现一个莫名的异常“java.io.IOException: RandomAccessSource not opened”,问度娘吧,没有找到合理的解决办法。然后就可以研究代码,从代码上看,真没什么问题啊。

之后就不禁怀疑,是不是哪里的流关早了,还是不该关的流关错了。

从堆栈信息来看,发现异常是打在pdfStamper.close()方法上的,

最后查看代码,在关闭stamper之前,关闭了构建stamper对象的os和reader,如下:

最后将stamper.close()放到最上边,即先关闭stamper,在关闭os和reader,测试一下,完美解决!!!终于可以歇歇了

RandomAccessSource not opened相关推荐

  1. JAVA itext 多种文件转pdf,进行合并 添加水印

    结合网上各路大神代码汇总而来,如果需要将pdf统一格式,可将pdf转成图片后重新转为pdf合并至一起,使用itext的PdfCanvas未成功解决该问题,主要也是因为我菜且时间紧没空查文档了.对于it ...

  2. The file “Info.plist” couldn’t be opened because there is no such file

    修改了Info.plist的实际文件位置(项目和单元测试对应不同的Info.plist),报错 (null): could not read data from '/Users/xxxxx/Deskt ...

  3. “XXXXX” is damaged and can’t be opened. You should move it to the Trash 解决方案

    苹果为了我们的软件安全也是操碎了心,很多小伙伴发现下载自各种第三方的软件在使用时都会弹出: "XXXXX" is damaged and can't be opened. You ...

  4. “Can’t be opened because Apple cannot check it for malicious software“ 解决方案

    "Can't be opened because Apple cannot check it for malicious software" 解决方案 参考文章: (1)" ...

  5. class path resource [beans.xml] cannot be opened because it does not exist

    严重: Exception sending context initialized event to listener instance of class org.springframework.we ...

  6. 解决spring的xml文件cannot be open ( class path resource cannot be opened)

    xml文件一直显示cannot be open 报错语句有一条: class path resource [bean2.xml] cannot be opened because it does no ...

  7. This file can not be opened as a file descriptor; it is probably compressed

    链接:FileNotFoundException: This file can not be opened as a file descriptor; it is probably compresse ...

  8. 【错误解决】[Maven] cannot be opened because it does not exist错误[文件无法编译到target目录下的解决方法]...

    转载请注明出处:http://blog.csdn.net/qq_26525215 本文源自[大学之旅_谙忆的博客] 使用IDEA搭建的Maven项目,在写SpringEL和资源调用时出现了如下错误: ...

  9. Storyboard.storyboard could not be opened. Could not read the archive.

    Storyboard.storyboard could not be opened. Could not read the archive.  Please use a newer version o ...

  10. VS2005、VS2010等VS系列IDE在MFC开发过程中,Resource View标签打不开,问题为“opened in other editor”

    问题描述: VS2005.VS2010等VS系列IDE在MFC开发过程中,Resource View标签打不开,问题为"opened in other editor" 可能原因: ...

最新文章

  1. tongweb安装部署_Linux系统东方通部署iserver说明
  2. 通过电脑给继电器发送指令_三菱FX PLC学习之通信指令(上)
  3. WebLogic中文博客
  4. mysql分片库分页查询_mysql数据库分页查询优化
  5. 一天一个设计模式之建造者模式(Builder)
  6. 《大数据》第1期——创刊寄语
  7. spring 5.x(1)-----Spring Framework 5.x中的新功能
  8. 【词向量】从Word2Vec到Bert,聊聊词向量的前世今生(一)
  9. Linq中Average,Sum等方法的使用解析
  10. 防盗链与token运用
  11. 通过分区(Partitioning)提高Spark的运行性能
  12. java session机制_如何学习Session的机制使用
  13. firefox vimperator (图)
  14. Win11 WSA 安卓子系统 下载安装更新
  15. uniapp 自定义头部 支持微信、百度、头条小程序
  16. Android应用自启动保活手段与安全现状分析
  17. Java 实现回文数
  18. 跟着别人学学优化自己的Ubuntu 操作系统
  19. 程序猿思维释放:打破常态
  20. 操作系统之文件管理(一)

热门文章

  1. App Tamer for Mac(CPU优化电池管理工具)特别版
  2. TCP Congestion性能测试分析
  3. FlexBox 行间距
  4. 人工智能管家机器人应当具备哪些功能?拥有家电控制能力是优势
  5. 基于三层交换技术的校园网设计与实现
  6. 双色F3.75LED点阵屏中保护电路74HC04的作用
  7. 如何判断三极管的集电极,基极和发射极?
  8. Django Q查询
  9. neo4j springboot 日志_springBoot 与neo4j的简单整合示例
  10. 青岛科技大学计算机转专业,2021年青岛科技大学大一新生转专业及入学考试相关规定...