android--detect if the TXT file contains double-byte characters

Source: Internet
Author: User

When reading double-byte characters, it mainly involves the selection of encodings:

Java code
  1. Public Static Boolean isrightfultxt (File f) {
  2. //TODO auto-generated method stub
  3. String regexp="[^\\x00-\\xff]"; Double-byte characters
  4. Pattern P=pattern.compile (regexp);
  5. try {
  6. FileInputStream fis=New FileInputStream (f);
  7. //"GBK" encoding supports double-byte characters
  8. InputStreamReader isr=New InputStreamReader (FIS, "GBK");
  9. BufferedReader br=New BufferedReader (ISR);
  10. String line="";
  11. While ((Line=br.readline ()) =null) {
  12. //Read file by line,
  13. //Retrieves whether the file contains double-byte characters
  14. Matcher M=p.matcher (line);
  15. if (M.find ()) {
  16. Fis.close ();
  17. Isr.close ();
  18. Br.close ();
  19. return false;
  20. }
  21. }
  22. Fis.close ();
  23. Isr.close ();
  24. Br.close ();
  25. } catch (FileNotFoundException e) {
  26. //TODO auto-generated catch block
  27. E.printstacktrace ();
  28. } catch (Unsupportedencodingexception e) {
  29. //TODO auto-generated catch block
  30. E.printstacktrace ();
  31. } catch (IOException e) {
  32. //TODO auto-generated catch block
  33. E.printstacktrace ();
  34. }
  35. return true;
  36. }

The above code function: detect whether the TXT file contains double-byte characters, if there is a return false, otherwise return true.

android--detect if the TXT file contains double-byte characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.