Home > Java > JavaBase > body text

Garbled code problem in java char array output

coldplay.xixi
Release: 2020-10-20 10:50:05
Original
3095 people have browsed it

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

Garbled code problem in java char array output

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] = &#39;0&#39;;
}
Copy after login

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!

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