将String转换为InputStream,如何将InputStream转换为String

来源:互联网 发布:百度搜索引擎优化方案 编辑:程序博客网 时间:2024/05/19 17:08
1, ByteArrayInputStream   bais   =   new   ByteArrayInputStream(str.getBytes());         2, length的意思是输入流的长度,可以读文件、字节数组等的长度得到。         3,     InputStream   到String的转换一种方法是依次读出所有字节.2,     你要存储进数据的是什么呢?文件?内存的字节数组?     如果是后者读数组长度就可以了。如果是前者:先建一个文件File对象,取这个对象的length方法()。         3,     byte   b;     ByteArrayOutputStream   baos   =   new   ByteArrayOutputStream();     while((b=inpputstrea.read())!=-1){             baos.write(b);     }     return   baos.toString();