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.
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] = '0'; }
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!