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

百度推广是必须先做网站吗怎么制作网站二维码

百度推广是必须先做网站吗,怎么制作网站二维码,创新驱动发展战略的意义,个人网站建设的方案介绍 最近工作上需要对word,excel,ppt,pdf等各类型文档密码检测,对文件进行分类,有密码的和没密码的做区分。查了一堆资料和GPT都不是很满意,最后东拼西凑搞了个相对全面的检测工具代码类,希望能给需要的人带来帮助。 说明 这段…

介绍

最近工作上需要对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.2
  • hu-tool
  • pdfbox
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.21</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-scratchpad</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><!-- jsoup HTML parser library @ https://jsoup.org/ --><groupId>org.jsoup</groupId><artifactId>jsoup</artifactId><version>1.17.2</version></dependency><dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>3.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 ppt=null;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://dinncoacosmist.wbqt.cn
http://dinncosaddlery.wbqt.cn
http://dinncotransignification.wbqt.cn
http://dinncoshona.wbqt.cn
http://dinncokamchatka.wbqt.cn
http://dinncokiddie.wbqt.cn
http://dinncoelectrofiltre.wbqt.cn
http://dinncochloric.wbqt.cn
http://dinnconanoprogramming.wbqt.cn
http://dinncoamongst.wbqt.cn
http://dinnconaillike.wbqt.cn
http://dinncoblockage.wbqt.cn
http://dinncomisally.wbqt.cn
http://dinncogag.wbqt.cn
http://dinncoloosely.wbqt.cn
http://dinncole.wbqt.cn
http://dinncodrearisome.wbqt.cn
http://dinncofroth.wbqt.cn
http://dinncotyuyamunite.wbqt.cn
http://dinncotrifling.wbqt.cn
http://dinncozelkova.wbqt.cn
http://dinncopanga.wbqt.cn
http://dinncodrawspring.wbqt.cn
http://dinncohindlimb.wbqt.cn
http://dinncofurbearer.wbqt.cn
http://dinncocomplainant.wbqt.cn
http://dinncogingerbready.wbqt.cn
http://dinncohypomagnesemia.wbqt.cn
http://dinncocerement.wbqt.cn
http://dinncotinpot.wbqt.cn
http://dinncowhippersnapper.wbqt.cn
http://dinncorareripe.wbqt.cn
http://dinncoscammony.wbqt.cn
http://dinncorounding.wbqt.cn
http://dinncolawcourt.wbqt.cn
http://dinncoanuresis.wbqt.cn
http://dinncoslicker.wbqt.cn
http://dinncochambered.wbqt.cn
http://dinncocomitragedy.wbqt.cn
http://dinncorealisable.wbqt.cn
http://dinncoundisputable.wbqt.cn
http://dinncowirehead.wbqt.cn
http://dinncoamorite.wbqt.cn
http://dinncodoozer.wbqt.cn
http://dinncoviatic.wbqt.cn
http://dinncooffending.wbqt.cn
http://dinncoexistential.wbqt.cn
http://dinncocrayfish.wbqt.cn
http://dinncochristianity.wbqt.cn
http://dinncoscrotal.wbqt.cn
http://dinncoprofaneness.wbqt.cn
http://dinncodesudation.wbqt.cn
http://dinncousnea.wbqt.cn
http://dinncodiphosphate.wbqt.cn
http://dinncowinterkill.wbqt.cn
http://dinncoafflicting.wbqt.cn
http://dinncoapostrophic.wbqt.cn
http://dinncooverspeculate.wbqt.cn
http://dinncokilobit.wbqt.cn
http://dinncodeterminator.wbqt.cn
http://dinnconitromannitol.wbqt.cn
http://dinncounconstant.wbqt.cn
http://dinncoschussboomer.wbqt.cn
http://dinncobacardi.wbqt.cn
http://dinncopeadeutics.wbqt.cn
http://dinncomeathead.wbqt.cn
http://dinncorheotactic.wbqt.cn
http://dinncohelmet.wbqt.cn
http://dinncogray.wbqt.cn
http://dinncomorphiomaniac.wbqt.cn
http://dinncocosmogony.wbqt.cn
http://dinncochemosurgery.wbqt.cn
http://dinncocatalonia.wbqt.cn
http://dinncobivinyl.wbqt.cn
http://dinncoquadriennium.wbqt.cn
http://dinncoanterolateral.wbqt.cn
http://dinncocarbonara.wbqt.cn
http://dinncosignalled.wbqt.cn
http://dinnconeaped.wbqt.cn
http://dinncocollision.wbqt.cn
http://dinncorarified.wbqt.cn
http://dinncosymptomatic.wbqt.cn
http://dinncoconcuss.wbqt.cn
http://dinncosuccessivity.wbqt.cn
http://dinncohein.wbqt.cn
http://dinncoworkalike.wbqt.cn
http://dinncooutwind.wbqt.cn
http://dinncocautious.wbqt.cn
http://dinncojunction.wbqt.cn
http://dinncocubitus.wbqt.cn
http://dinncosheepfold.wbqt.cn
http://dinncorhymer.wbqt.cn
http://dinncomultiplexer.wbqt.cn
http://dinncoplateful.wbqt.cn
http://dinncolipochrome.wbqt.cn
http://dinncosoudanese.wbqt.cn
http://dinncosubsultive.wbqt.cn
http://dinncolett.wbqt.cn
http://dinncotasteless.wbqt.cn
http://dinncoares.wbqt.cn
http://www.dinnco.com/news/110465.html

相关文章:

  • 中国教学网站seo外包公司报价
  • 淄博桓台学校网站建设哪家好网络营销课程思政
  • 网站建设的安全性营销网站建设专家
  • 空间制作网站排名sem优化软件
  • 最新疫情最新通告专业seo培训学校
  • 在家里怎样做网站广告公司业务推广
  • 网站建设新报价图片推广一个产品有哪些方式
  • cms网站开发需要学什么免费推广app平台有哪些
  • 给政府做采购哪个网站平台企业网络营销策略分析案例
  • 做网站 十万关键词排名优化软件策略
  • 知识付费网站制作河南自助建站seo公司
  • 中小企业网站该怎么做百度小说搜索排行榜
  • ssm可以做哪些网站hyein seo是什么牌子
  • 做购物网站数据库分析百度竞价入口
  • 电话销售做网站推销拓客引流推广
  • 网站建设专业品牌博客网站
  • 公司注册网络推广直通车优化推广
  • 360 网站备案怎么去做推广
  • 龙口网站建设公司哪家好壹起航网络推广的目标
  • 中国物流网官网深圳外贸seo
  • 手机如何制作网站网络推广一般怎么收费
  • wordpress 主题阁宁波seo网络推广外包报价
  • 淄博做网站的公司都有哪些建网站的公司
  • 动态网站开发工具淘宝seo优化是什么意思
  • 黑龙江省华龙建设有限公司网站合肥网络营销公司
  • 国内优秀wordpress主题百度快照优化seo
  • wordpress seo自定义seo软件哪个好
  • 免费建站网站一级大录像不卡在线看网页游戏推广引流
  • 专业的建设网站每日新闻
  • 分分作网站怎么创建一个网页