1、String与InputStream转换

(1)String -> InputStream

 
  1. String   str   =   "hello world"
  2. InputStream   inputStream   =   new   ByteArrayInputStream(str.getBytes()); 

(2)InputStream -> String

 
  1. byte   b;  
  2. ByteArrayOutputStream   baos   =   new   ByteArrayOutputStream();  
  3. while((b=inpputstrea.read())!=-1){  
  4.         baos.write(b);  
  5. }  
  6. return   baos.toString();