String.getbytes () is the conversion of a string into a byte array. String.tochararray () converts a string into an array of characters.
For example
byte bys[] = "National Day 60 Anniversary". GetBytes ();
Char chs[]= "National Day 60 Anniversary". ToCharArray ();
"So what's the difference between a byte array and a character array?" 】
The Read and write methods of the byte input stream and output stream use byte arrays to read and write data, that is, to process the data in bytes as basic clerk. Therefore, the byte stream does not work well with Unicode characters, for example, a Chinese character occupies 2 bytes in a file, and if a byte stream is used, improper reading can result in a "garbled" phenomenon. BYTE classes FileInputStream and FileOutputStream are classes under IO, while the character output stream FileReader and the character input stream filewriter are both reader and writer subclasses.
When you create an output stream that points to a file using the construct method, if the parameter append evaluates to True, the output stream does not flush the file pointed to (if the file already exists), the Wirite method of the output stream starts writing data to the file from the end of the file, the parameter append evaluates to False, The output stream refreshes the file pointed to (if the file already exists). Append with refresh function;
For writer streams, the Write method writes the data to the buffer first, and whenever the buffer overflows, the contents of the buffer are automatically written to the destination, and if the stream is closed, the contents of the buffer are immediately written to the destination. A stream call Flush () (not flash) can flush the current buffer immediately, writing the contents of the current buffer to the destination.
String.getbytes () and String.tochararray (), the difference between byte arrays and character arrays