当前位置: 首页 > news >正文

java 通过文件下载地址读取文件内容

需求:读取文件内容,已知文件下载地址
需要引入pdfbox依赖

<dependency>
<groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>2.0.27</version>
</dependency>

@Override
public MesDataRespVO addPasterLabel(PasterLabelReqVO reqVO) {String downloadUrl = "文件下载地址";reqVO.setPaterLabelUrl(downloadUrl);PDDocument document = null;InputStream inputStream = null;try{URL url = new URL(downloadUrl);HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 设置超时时间20秒conn.setConnectTimeout(20 * 1000);inputStream = conn.getInputStream();document = PDDocument.load(inputStream);int pageSize = document.getNumberOfPages();String text = "";// 一页一页读取for (int i = 0; i < pageSize; i++) {// 文本内容PDFTextStripper stripper = new PDFTextStripper();// 设置按顺序输出stripper.setSortByPosition(true);stripper.setStartPage(i + 1);stripper.setEndPage(i + 1);text = stripper.getText(document);System.out.println(text.trim());}}catch (Exception e){log.error(e.getMessage(),e);}finally {try {if (document != null) {document.close();}if(inputStream != null){inputStream.close();}} catch (IOException e) {log.error(e.getMessage(), e);}}return null;
}
http://www.lryc.cn/news/437553.html

相关文章:

  • 打造古风炫酷个人网页:用HTML和CSS3传递笔墨韵味
  • vue 项目自适应 配置 px转rem 的插件postcss-pxtorem
  • 股票程序化交易是,第三方软件申请券商私有接口API的门槛
  • JDK8的一些主要的新特性
  • 40岁的java程序员,还有出路吗?
  • 【服务器】shell脚本之Docker创建nginx
  • 提取蛋白质复合体结构中组装体的变换矩阵
  • java程序员入行科目一之CRUD轻松入门教程(一)
  • OpenHarmony鸿蒙开发( Beta5.0)智能油烟机开发实践
  • 【GBase 8c V5_3.0.0 分布式数据库常用维护命令】
  • 破解AI生成检测:如何用ChatGPT降低论文的AIGC率
  • Python用MarkovRNN马尔可夫递归神经网络建模序列数据t-SNE可视化研究
  • setup函数子传父普通写法
  • seafaring靶场漏洞测试攻略
  • 简单示例,搞懂PowerBI的ALL(),ALLEXCEPT()和ALLSELECTED()的区别
  • Collection
  • 19章 泛型
  • 基于python+django+mysql+Nanodet检测模型的水稻虫害检测系统
  • 计算机网络27、28——Linux命令1、2
  • 【Python深度学习】逆强化学习(IRL):通俗揭开学习背后的奥秘
  • Linux:五种IO模型
  • ansible企业实战
  • 面向对象程序设计之模板进阶(C++)
  • 电巢科技携Ecosmos元宇宙产品亮相第25届中国光博会
  • Redis 入门 - 收官
  • Windows技术栈企业基础底座(1)-为基于Windows的Nginx安装证书
  • ThreeJS入门(002):学习思维路径
  • 基于ssm+vue+uniapp的新生报到系统小程序
  • 掌握 JavaScript ES6+:现代编程技巧与模块化实践
  • AttackGen - AI 网络安全事件响应测试工具,附下载链接