Loading

request.getInputStream() 的两种解析方式

 

http://sagewsg.iteye.com/blog/1717923

 

byte[] bytes = new byte[1024 * 1024];
        InputStream is;
        try {
            is = request.getInputStream();
            int nRead = 1;
            int nTotalRead = 0;
            while (nRead > 0) {
                nRead = is.read(bytes, nTotalRead, bytes.length - nTotalRead);
                if (nRead > 0)
                    nTotalRead = nTotalRead + nRead;
            }
            String str = new String(bytes, 0, nTotalRead, "utf-8");
            System.out.println("Str:" + str);
            res = str;
            is.close();
            is = null;
        } catch (IOException e) {
            e.printStackTrace();
        }

 

posted @ 2017-03-16 18:54  stono  阅读(5500)  评论(0编辑  收藏  举报