In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to read the Java file containing Chinese, I hope you will gain something after reading this article, let's discuss it together!
The problem that had been tortured for a day was finally solved at dusk, and now spit it out.
As we all know, the Chinese problem of java has always been a difficult problem, which can be seen in the question rate of Chinese garbled in the java forum in csdn. Even the software giant IBM has opened a special area to solve Chinese problems as a layman (always dreamed of becoming a "fake god" like Kim Kelly, but never succeeded, perhaps because God does not take care of China) I was also troubled by the problem of consent, but fortunately it was solved today.
With my complete abandonment of the .NET platform (only forced by life, after all, I still have to live), transferring the original resources to the Java platform is one of my current important tasks. At this point, I have to admit that .net is very good at solving Chinese problems, although there are occasional garbled codes.
The problem is this, my box (http://www.ibeyond.org/box/) was originally written using ASP.net (at that time just to try a new technology), at that time I gave up using the database for the portability of the data, and saved all the data as UTF-8-encoded text files. Net to read this file order as long as you specify how to open the file encoding, the Chinese problem can be avoided. But according to my previous thinking, this is not done in java. In java, it is read first and then converted, and the final result proves me wrong. It seems that the idea of experience kills people.
File f=new File ((new BoxConfig ()) .getBaseDir () + "Data" + request.getParameter ("ID") + ".inc"); XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" / >
BufferedReader reader = new BufferedReader (new FileReader (f))
String line
While ((line=reader.readLine ())! = null) {
StrContent+=line
}
This is my original code, f, which is the text file in UTF-8 format that I want to read. Countless attempts have been made during the day, including new String (strContent.getBytes ("UTF-8")) (N transcoding attempts), System.setProperty ("file.encoding", "UTF-8") (where N transcoding is specified), and failed. Among them, I believe that all of you who have been tortured by the procedure know something about it. I will skip it here. Finally, I got a piece of information that proved to be very important in countless queries in google, "specify character encoding when reading the file", which reminds the dreamer, isn't it realized in .net? After a detour, the problem was finally solved.
File f = new File ("E:EclipseworkspaceboxData2003" > 2003-3-7-100.inc ")
InputStreamReader read = new InputStreamReader (new FileInputStream (f), "UTF-8")
BufferedReader reader=new BufferedReader (read)
String line
While ((line = reader.readLine ())! = null) {
System.out.println (line)
}
This problem is easily solved by opening the file to specify the file encoding.
After reading this article, I believe you have a certain understanding of "how to read Chinese in Java file". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.