java关于io的问题

LuxBai 2015-06-19 11:47:48

String xml = "";
URLConnection connection = url.openConnection();
HttpURLConnection httpconn = (HttpURLConnection) connection;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
bout.write(xml.getBytes());
OutputStream out = httpconn.getOutputStream();
out.write(b);


为什么不直接用out.write(xml.getBytes());而是先将xml写入流中,在从流中生成数组,再写入流中
...全文
148 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
LuxBai 2015-06-19
  • 打赏
  • 举报
回复
为什么不直接用out.write(xml.getBytes());
  • 打赏
  • 举报
回复
我不知道你代码全不全,但是大体上来说,ByteArrayOutputStream 是有缓冲区的,随着不断写入,不断增加,而且write方法是线程安全的。

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧