Dedian  
-- 关注搜索引擎的开发
日历
<2014年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
统计
  • 随笔 - 82
  • 文章 - 2
  • 评论 - 228
  • 引用 - 0

导航

常用链接

留言簿(8)

随笔分类(45)

随笔档案(82)

文章档案(2)

Java Spaces

搜索

  •  

积分与排名

  • 积分 - 65025
  • 排名 - 816

最新评论

阅读排行榜

评论排行榜

 
1. String --> InputStream

InputStream convertToInputStream(String str)
{
        ByteArrayInputStream is = new ByteArrayInputStream(str.getBytes());
        return is;
}

2. InputStream --> String
    
String convertToString(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();
           
}

When I do the socket programming, I always need to deal with inputstream and string, above are the basic ways to so that, but I am not sure if there are any simpler ways to do that...

posted on 2006-04-29 05:17 Dedian 阅读(620) 评论(3)  编辑  收藏 所属分类: Java Memo
评论:
  • # re: convertion between InputStream & String  zhangzhuang Posted @ 2006-09-05 15:11
    thank you!~  回复  更多评论   

  • # re: convertion between InputStream & String  http://www.bc-fermetures.fr Posted @ 2014-11-29 12:04
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    StringBuffer buffer = new StringBuffer();  回复  更多评论   

  • # re: convertion between InputStream & String  http://www.bc-fermetures.fr Posted @ 2014-12-04 11:06
    BufferedReader in = new BufferedReader(new InputStreamReader(is));
    StringBuffer buffer = new StringBuffer();  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © Dedian Powered by: 博客园 模板提供:沪江博客