Create InputStreamReader from InputStream and read string - Android java.io

Android examples for java.io:InputStreamReader

Description

Create InputStreamReader from InputStream and read string

Demo Code

import android.content.res.Resources;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main{

    public static String loadString(InputStream is) throws IOException {
        StringBuilder builder = new StringBuilder();
        InputStreamReader reader = new InputStreamReader(is);
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            builder.append(buf, 0, numRead);
        }//from   w ww  .j av a 2 s . co m
        return builder.toString();
    }

}

Related Tutorials