The JDK itself comes with an API that gets the length of the string byte, but if the string contains special symbols or full-width symbols or punctuation, the result is biased, and the best evidence is Sina Weibo's word count.
JDK fetch byte length //Note getBytes () is obtained by default in the file encoding format of bytes, usually UTF-8 (can look at the API), different encoding format of bytes, the length obtained is also different, I have personally tested it, it is recommended to obtain a bytes length with the specified encoding format, such as: GetBytes ("UTF-8")int length = new String (). GetBytes (). length; If the content contains newline characters, tabs, carriage returns and other symbols, to remove, you can use the following code://Clean up the content of useless newline characters and so on to get more accurate length
content = Content.replaceall ("[\r\n\t]", ""); In order to solve this problem, perfect found a solution
Two ways to get string lengths by Byte in Java