日期:2014-05-20 浏览次数:20722 次
/** * 读流生成byte[],全读取 * * @param is * @return */ public static byte[] readFully(InputStream is) { byte[] bytes = null; if (is != null) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int l = 0; byte[] b = new byte[1024]; while ((l = is.read(b)) != -1) { baos.write(b, 0, l); } bytes = baos.toByteArray(); baos.close(); baos = null; } catch (IOException e) { e.printStackTrace(); } } return bytes; }
------解决方案--------------------
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.out.println("baos=="+baos);
这时候还没往里头写数据呢,当然是空的...
你要根据返回的byte[]是不是空来判断有没有数据
------解决方案--------------------
byte[] bstr=readFully(is);
str=new String(bstr,"UTF-8");
System.out.println("str=="+str);