write之getBytes()
void java.io.OutputStream.write(byte[] b) throws IOException
-
write
public void write(byte[] b) throws IOExceptionWritesb.lengthbytes from the specified byte array to this output stream. The general contract forwrite(b)is that it should have exactly the same effect as the callwrite(b, 0, b.length).- Parameters:
b- the data.- Throws:
IOException- if an I/O error occurs.- See Also:
write(byte[], int, int)
getBytes()是将一个字符串转化为一个字节数组。
String的getBytes()方法是得到一个系统默认的编码格式的字节数组。将一个string类型的字符串中包含的字符转换成byte类型并且存入一个byte数组中。在java中的所有数据底层都是字节,字节数据可以存入到byte数组。存储字符数据时(字符串就是字符数据),会先进行查表,然后将查询的结果写入设备,读取时也是先查表,把查到的内容打 印到显示设备上,getBytes()是使用默认的字符集进行转换,getBytes(“utf-8”)是使用UTF-8编码表进行转换。

浙公网安备 33010602011771号