Converts a InputStream to String. - Android File Input Output

Android examples for File Input Output:InputStream

Description

Converts a InputStream to String.

Demo Code


//package com.java2s;

import android.util.Log;

public class Main {
    private static final String TAG = "WebUtils";

    /**//  w  w w  . j av a 2  s. com
     * Converts a InputStream to String. 
     * Taken from http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
     * @param is the InputStream to be converted
     * @return the resulting String
     */
    public static String convertStreamToString(java.io.InputStream is) {
        Log.d(TAG, "convertStreamToString");
        java.util.Scanner s = new java.util.Scanner(is, "UTF-8")
                .useDelimiter("\\A");
        return s.hasNext() ? s.next() : "";
    }
}

Related Tutorials