read String From Stream - Java File Path IO

Java examples for File Path IO:File Stream

Description

read String From Stream

Demo Code


//package com.java2s;
import java.io.*;

public class Main {
    public static String readStringFromStream(InputStream inputStream) {
        String text;/*  w  w w .jav  a  2 s. co  m*/
        InputStreamReader reader = new InputStreamReader(inputStream);
        try {
            text = getString(reader);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return text;
    }

    private static String getString(Reader reader) throws IOException {
        String text = "";
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            text += line + "\n";
        }
        return text;
    }
}

Related Tutorials