read Stream As String - Android File Input Output

Android examples for File Input Output:Text File

Description

read Stream As String

Demo Code


//package com.java2s;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    private static String readStreamAsString(InputStream in) {
        BufferedReader reader = null;
        StringBuilder builder = new StringBuilder();
        try {//ww  w . j av  a  2 s  . c  o  m
            reader = new BufferedReader(new InputStreamReader(in));
            String line = "";
            while ((line = reader.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //close reader
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return builder.toString();
    }
}

Related Tutorials