黑马程序员技术交流社区

标题: 大神们关于JAVA IO中内存操作流的一个问题 [打印本页]

作者: 马蚁牙黑    时间: 2016-9-3 23:07
标题: 大神们关于JAVA IO中内存操作流的一个问题
import java.io.* ;
public class ByteArrayDemo01{
        public static void main(String args[]){
                String str = "HELLOWORLD" ;                // 定义一个字符串,全部由大写字母组成
                ByteArrayInputStream bis = null ;        // 内存输入流
                ByteArrayOutputStream bos = null ;        // 内存输出流
                bis = new ByteArrayInputStream(str.getBytes()) ;        // 向内存中输出内容
                bos = new ByteArrayOutputStream() ;        // 准备从内存ByteArrayInputStream中读取内容
                int temp = 0 ;
                while((temp=bis.read())!=-1){
                        char c = (char) temp ;        // 读取的数字变为字符
                        bos.write(Character.toLowerCase(c)) ;        // 将字符变为小写
                }
                // 所有的数据就全部都在ByteArrayOutputStream中
                String newStr = bos.toString() ;        // 取出内容
                try{
                        bis.close() ;
                        bos.close() ;
                }catch(IOException e){
                        e.printStackTrace() ;
                }
                System.out.println(newStr) ;
        }
};
bos.toString() 是怎么取出内容的,难道是 ByteArrayOutputStream()类重写了.toString()方法,另外bos.write(Character.toLowerCase(c))这句话最终有没有将“helloworld”表示为bos对象的字符串

作者: tiamo305    时间: 2016-9-3 23:08
靠靠靠靠靠靠靠靠
作者: 马蚁牙黑    时间: 2016-9-3 23:12
tiamo305 发表于 2016-9-3 23:08
靠靠靠靠靠靠靠靠

大神们关于JAVA IO中内存操作流的一个问题
http://bbs.itheima.com/thread-323389-1-1.html
(出处: 黑马程序员IT技术论坛)

作者: 18317715134    时间: 2016-9-4 18:34
不错  继续努力啊
作者: 马蚁牙黑    时间: 2016-9-4 18:47
18317715134 发表于 2016-9-4 18:34
不错  继续努力啊

可以可以
作者: 马蚁牙黑    时间: 2016-9-4 18:58
tiamo305 发表于 2016-9-3 23:08
靠靠靠靠靠靠靠靠

可以小伙子干的不错
作者: zhangyawei2016    时间: 2016-9-4 19:10
黑马小伙厉害!!!!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2