Solution to java char array output garbled code: initialization is required when declaring the array, the code is [char buf[] = new char[200];for(int i = 0; i < 200; i ) {buf[i] = '0';}】
Solution to Java char array output garbled code:
Today when I was writing a socket, I transmitted a string through the network. When I read it out, I stored a char string. Then when I output the array, I found a problem (I have encountered it before), that is, in addition to the information that should be output , and a lot of boxes were output~~~
I checked the garbled characters on the Internet, and it was said to be an encoding problem, but it is not. The solution is very simple. You must initialize it when declaring the array! !
char buf[] = new char[200]; for(int i = 0; i < 200; i++){ buf[i] = '0'; }
Otherwise similar problems will occur! !
Related free learning recommendations: java basic tutorial
The above is the detailed content of Garbled code problem in java char array output. For more information, please follow other related articles on the PHP Chinese website!