String Reader InputStream   Leave a comment

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

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();
}

 
String –> Reader
Reader reader = new StringReader(string);
 
Reader –> String
 
BufferedReader br = new BufferedReader(reader);
  String temp = null;
  StringBuffer sb = new StringBuffer();
  while((temp=br.readLine())!=null){
   sb.append(temp+"\n");
  }
  String string = sb.toString();
 

Posted 2009年12月8日 by gw8310 in 未分类

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: