String与InputStream互转(转)

来源:互联网 发布:听歌软件 编辑:程序博客网 时间:2024/06/06 07:32

//String转inputStream1. String --> InputStreamInputStream String2InputStream(String str){    ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());    return stream;} 2. InputStream --> StringString 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();}InputStream inputStream = postMethod.getResponseBodyAsStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); String xml = FileCopyUtils.copyToString(in);
 http://congjl2002.iteye.com/blog/169599
0 0