How to Create a string from a BufferedInputStream using bytes?

This question already has an answer here:

  • Read/convert an InputStream to a String 56 answers

  • The buffer is too large. Try this:

        InputStream content = new FileInputStream(file);
    
        int numRead;
        final int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];
        ByteArrayOutputStream outString = new ByteArrayOutputStream();
        try{
            while ((numRead = content.read(buffer)) != -1) {
                outString.write(buffer, 0, numRead);
            }
        } finally {
            content.close();
        }
        return new String(outString.toByteArray());
    
    链接地址: http://www.djcxy.com/p/13734.html

    上一篇: 如何在Android中返回FileInputStream的值

    下一篇: 如何使用字节从BufferedInputStream创建字符串?