String和InputStream转换

来源:互联网 发布:地理国情普查数据库 编辑:程序博客网 时间:2024/05/18 19:20

1. String --> InputStream

  1. InputStream StringToInputStream(String str){   
  2.     ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes());   
  3.     return stream;   
  4. }  

 

InputStream --> String

 

  1. String inputStreamToString(InputStream is){   
  2.     BufferedReader in = new BufferedReader(new InputStreamReader(is));   
  3.     StringBuffer buffer = new StringBuffer();   
  4.     String line = "";   
  5.     while ((line = in.readLine()) != null){   
  6.         buffer.append(line);   
  7.     }   
  8.     return buffer.toString();   

原创粉丝点击