String和InputStream的转换

科牛

关注

阅读 131

2022-11-22



1. String --> InputStream

InputStream String2InputStream(String str){
ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());
return stream;
}

 

2. InputStream --> String

String inputStream2String(InputStream is){
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null){
buffer.append(line);
}
return buffer.toString();
}

 


精彩评论(0)

0 0 举报