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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM