Home  >  Article  >  Java  >  What to do if java char array outputs garbled characters

What to do if java char array outputs garbled characters

coldplay.xixi
coldplay.xixiOriginal
2020-08-17 11:51:223519browse

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;;
}

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!

Statement:
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