关于PrintWriter的flush()方法
在web编程中需要返回数据给客户端时都是采用PrintWriter,获取一个输出流对象采用以下方法!奇怪的是当调用了flush()方法后,会在返回的数前面加上一个以16进制表示的数据大小,以及最后面加个0,请问这是怎么回事?谁给我解释下!做这客户端那边的老大给我下难题了,要我给他个合理解释为什么会这样!
response.setContentType("text/xml");response.setCharacterEncoding("utf-8");PrintWriter out=null;try { out=response.getWriter(); msg.append("<data>"); msg.append(sbf.toString()); msg.append("</data>");} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();}out.print(msg.toString());out.flush();//加上这个就会在数据前自动加上大小及最后一个0out.close();HTTP/1.1 200 OKDate: Wed, 27 Jun 2012 05:26:51 GMTServer: Apache/2.2.22 (FreeBSD) PHP/5.2.6 with Suhosin-Patch mod_ssl/2.2.22 OpenSSL/0.9.7e-p1X-Powered-By: PHP/5.2.6Cache-Control: private, must-revalidate, max-age=0, proxy-revalidate, no-transformPragma: no-cacheVary: Accept-EncodingConnection: closeTransfer-Encoding: chunkedContent-Type: text/html[color=#FF0000]321e[/color]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--[71,88,7] published at 2012-06-19 16:22:21 from #187 by 6050--><!doctype html><html><head>