首页 > 技术文章 > request.getInputStream() 的两种解析方式

stono 2017-03-16 18:54 原文

 

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();
        }

 

推荐阅读