1、String –> InputStream
InputStream is = new ByteArrayInputStream(str.getBytes());
or
ByteArrayInputStream stream
= new ByteArrayInputStream(str.getBytes());
2、InputStream–>String
inputStream input;
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = input.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
out.toString();
3、Reader –>String
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = " ";
while ((line = in.readLine()) != null){
buffer.append(line);
}
return buffer.toString();
4、String–>Reader
StringReader stringReader = new StringReader(s);
String 、InputStream、Reader 之间的转换
最新推荐文章于 2022-03-16 16:57:02 发布