org.apache.commons.io.output.ByteArrayOutputStream
int i = -1;
//org.apache.commons.io.output.ByteArrayOutputStream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((i = is.read()) != -1) {
baos.write(i);
}
String content = baos.toString();
byte数组
int i = -1;
byte[] b = new byte[1024];
StringBuffer sb = new StringBuffer();
while ((i = is.read(b)) != -1) {
sb.append(new String(b, 0, i));
}
String content = sb.toString();
java中 将字符串 转成 inputstream 转换后如何查看inputstream的size
String str = "something";
Byte[] bytes = str.getBytes() ;
ByteArrayInputStream bais=new ByteArrayInputStream(bytes);
int size=bytes.lenghth;
将InputStream流转换成字符串
InputStream fs=fi.getInputStream();
int b;
//顺序读取文件text里的内容并赋值给整型变量b,直到文件结束为止。
StringBuffer sb=new StringBuffer();
while((b=fs.read())!=-1 ){
if((char)b=='\n'){
sb.append("回车");
}else{
sb.append((char)b);
}
}
out.println(sb.toString());