In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces apache tika how to detect whether the file is damaged, the article is very detailed, has a certain reference value, interested friends must read it!
Apache Tika is a library for file type detection and extraction of file contents from various formats.
When uploading a file to the server and parsing the file, it is often necessary to determine whether the file is damaged. We can use tika to detect file corruption
Maven introduces the following:
Org.apache.tika tika-app 1.18 xerces xercesImpl 2.11.0
If the jar package conflicts, you can introduce the following:
Org.apache.tika tika-core 1.18 org.apache.tika tika-parsers 1.18 xerces xercesImpl 2.11.0
Use tika to detect file corruption:
If reading from the input stream fails, the parse method throws an IOException exception, the document obtained from the stream cannot be parsed and a TikaException exception is thrown, and if the handler cannot handle the event, a SAXException exception is thrown
When a document cannot be parsed, it is corrupted
Execution process:
Public static void main (String [] args) {try {/ / Assume sample.txt is in your current directory File file = new File ("D:\\ test .txt"); boolean result = isParseFile (file);} catch (Exception e) {e.printStackTrace () }} / * verify that the file is corrupt * * @ param file file * @ return true/false * @ throws Exception * / private static boolean isParseFile (File file) throws Exception {try {Tika tika = new Tika (); String filecontent = tika.parseToString (file); System.out.println (filecontent); return true;} catch (TikaException e) {return false;}}
Output result:
Test data-read text content
The above is all the contents of the article "how to detect file corruption in apache tika". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.