码迷,mamicode.com
首页 > 其他好文 > 详细

write之getBytes()

时间:2016-04-08 18:12:40      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

void java.io.OutputStream.write(byte[] b) throws IOException

  • write

    public void write(byte[] b)
               throws IOException
    Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(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编码表进行转换。

write之getBytes()

标签:

原文地址:http://www.cnblogs.com/dier306/p/5369119.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!