Home > Java > javaTutorial > body text

What to do if java char array outputs garbled characters

coldplay.xixi
Release: 2020-08-17 11:51:22
Original
3592 people have browsed it

The solution to the garbled output of java char array: first create a java file; then be sure to initialize it when declaring the array; finally read it out and store it in a char type string, and output the array.

What to do if java char array outputs garbled characters

Solution to Java char array output garbled code:

When writing socket today, the string is transmitted through the network , a char string was stored when reading it out, and then when outputting the array, I found a problem (I have encountered it before), that is, in addition to the information that should be output, many boxes are also output

I checked the garbled characters on the Internet and said it was an encoding problem. In fact, it is not. The solution is very simple. You must initialize the array when declaring it! !

char buf[] = new char[200];
 
for(int i = 0; i < 200; i++){
buf[i] = &#39;0&#39;;
}
Copy after login

Otherwise similar problems will occur! !

Related learning recommendations: java basic tutorial

The above is the detailed content of What to do if java char array outputs garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!