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

一个网站3个相似域名查关键词排名

一个网站3个相似域名,查关键词排名,秦洁婷seo博客,青岛建设集团介绍 最近工作上需要对word,excel,ppt,pdf等各类型文档密码检测#xff0c;对文件进行分类#xff0c;有密码的和没密码的做区分。查了一堆资料和GPT都不是很满意#xff0c;最后东拼西凑搞了个相对全面的检测工具代码类#xff0c;希望能给需要的人带来帮助。 说明 这段…介绍 最近工作上需要对word,excel,ppt,pdf等各类型文档密码检测对文件进行分类有密码的和没密码的做区分。查了一堆资料和GPT都不是很满意最后东拼西凑搞了个相对全面的检测工具代码类希望能给需要的人带来帮助。 说明 这段代码提供了一个全面的工具类用于检测多种办公文档.xls, .xlsx, .doc, .docx, .pdf, .ppt, .pptx是否设置了密码保护。以下是该实现的核心逻辑和要点 1、通用检测入口通过isFileProtected(File file, String fileExtension)方法根据文件扩展名调用特定的检测方法。 2、Excel文件检测(isExcelProtected(File file)): 使用WorkbookFactory.create()尝试打开文件如果文件加密会抛出EncryptedDocumentException异常。 3、Word文件检测(isWordProtected(File file)): 利用WordExtractor尝试读取文件内容当文件加密时会抛出EncryptedDocumentException异常或者从异常信息中判断文件是否加密。 4、PDF文件检测(isPdfProtected(File file)): 使用PDFBox库的Loader.loadPDF()加载文件然后检查PDDocument实例的isEncrypted()状态或捕获InvalidPasswordException来判断是否加密。 5、PPT文件检测(isPptProtected(File file)): 对于.ppt文件使用HSLFSlideShow尝试读取通过捕获异常并检查消息中是否包含“encrypted”关键字来判断文件是否加密。注意对于.pptx文件理论上应该使用与.xlsx类似的处理方式但示例中未单独区分。 6、资源管理使用try-with-resources语句确保文件输入流和各种文档对象在操作完成后能被正确关闭同时利用自定义的IoUtil.close()方法进一步确保资源的释放假设这是您项目中的一个辅助方法。 7、日志记录在捕获异常时记录错误日志有助于追踪问题。 实现步骤 添加依赖 poi-4.1.2hu-toolpdfbox dependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion5.8.21/version/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi-scratchpad/artifactIdversion4.1.2/version/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion4.1.2/version/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion4.1.2/version/dependencydependency!-- jsoup HTML parser library https://jsoup.org/ --groupIdorg.jsoup/groupIdartifactIdjsoup/artifactIdversion1.17.2/version/dependencydependencygroupIdorg.apache.pdfbox/groupIdartifactIdpdfbox/artifactIdversion3.0.2/version/dependency工具类 public class TestFileEncrypt {private static final Logger log LoggerFactory.getLogger(TestFileEncrypt.class);public static void main(String[] args) {String filePath d:/tmp/enc/data0.xls; // 替换为你要检查的文件路径boolean isLikelyEncrypted isExcelProtected(FileUtil.newFile(filePath));System.out.println(文件是否加密的: isLikelyEncrypted);}// 创建通用方法根据文件后缀名识别文件类型调用不同的方法进行检测public static boolean isFileProtected(File file, String fileExtension) {switch (fileExtension.toLowerCase()) {case xls:case xlsx:return isExcelProtected(file);case doc:case docx:return isWordProtected(file);case pdf:return isPdfProtected(file);case ppt:case pptx:return isPptProtected(file);default:return false;}}// 检查XLSX文件是否受密码保护public static boolean isExcelProtected(File file) {boolean isProtected false;Workbook sheets null;try (FileInputStream fis new FileInputStream(file)) {sheets WorkbookFactory.create(fis);// 尝试打开XLSX文件sheets.close();} catch (EncryptedDocumentException e) {isProtected true; // 抛出异常表示文件受密码保护} catch (IOException e) {log.error(读取Excel文件失败{},{},file.getName(),e.getMessage());} finally {if (sheets ! null) {IoUtil.close(sheets);}return isProtected;}}public static boolean isWordProtected(File file) {boolean isProtected false;WordExtractor extractor null;try (FileInputStream fis new FileInputStream(file)) {// 创建WordExtractor以读取内容这一步可能会在文件受保护时失败extractor new WordExtractor(fis);extractor.close(); // 关闭提取器} catch (EncryptedDocumentException e){isProtected true;} catch (IOException e) {if(e.getMessage().indexOf(EncryptedPackage) ! -1){isProtected true;}else{log.error(读取Word文件失败{},{},file.getName(),e.getMessage());}} finally {if(extractor!null){IoUtil.close(extractor);}return isProtected;}}// 检查PDF文件是否受密码保护public static boolean isPdfProtected(File file) {boolean isEncrypted false;try (PDDocument document Loader.loadPDF(file)) {if (document.isEncrypted()) {isEncrypted true;}} catch (InvalidPasswordException e) {isEncrypted true;} catch (IOException e) {log.error(读取pdf文件失败{},{},file.getName(),e.getMessage());}finally {return isEncrypted;}}public static boolean isPptProtected(File file) {boolean isProtected false;HSLFSlideShow pptnull;try (FileInputStream fis new FileInputStream(file)) {ppt new HSLFSlideShow(fis);ppt.getPageSize();ppt.close();} catch (Exception e){if(e.getMessage().toLowerCase().indexOf(encrypted)!-1){isProtected true;}} finally {if(ppt!null){IoUtil.close(ppt);}return isProtected;}}}
http://www.hkea.cn/news/14431110/

相关文章:

  • 免费字体下载网站内蒙古网络公司有哪些
  • 济南制作网站的公司吗中国商标免费查询入口
  • 网站建设公司推荐q479185700顶上四川省工程建设信息官方网站
  • 网站开发与软件开发的区别免费静态网页模板下载
  • 网站推广工作淮安市住房和城乡建设局网站首页
  • 企业网站建设搜集资料天眼查企业查询下载
  • 网站建设与网页设计案例教程pdf下载域名信息备案管理系统查询
  • 企业网站建设文案案例个人网站做淘宝客教程
  • 如何设计网站步骤网站制作基础教程
  • 网站建设自查情况wordpress ip改域名
  • 百度智能小程序是什么wordpress极速优化
  • 淮安做网站的公司有哪些公司临沂百度seo
  • 西宁网站建设兼职如何使用手机看建设网站
  • 小偷程序做的网站能用吗建设一个购物网站的费用
  • 学习网站建设总结备案域名买卖
  • 有几家公司如何建设网站如何设计网站模板
  • 创建网站要钱吗专门做湘菜的网站
  • 百度爱采购网站官网荣茂网站建设
  • 沈阳手机网站制作汽车网站设计
  • 网站开发背景意义网站开发总结简写
  • 做网站金山设计很好看的网站
  • 做网站推广的联系方式装潢设计工作室
  • 用asp做网站遇到的问题大连开发区网站设计公司
  • 企业网站源码php外链网站是什么
  • 展示用网站模板北滘网站建设
  • 橙色企业网站模板logo设计软件在线制作
  • 做外贸一般要注册哪些外贸网站有没有做淘宝客网站的
  • 网站留言板的作用用html5做商城网站怎么做
  • php网站后台反应慢怎么解决长沙做网站团队
  • 如何用cms做网站wap网站在线生成