get String in lines from InputStream - Java java.io

Java examples for java.io:InputStream Read

Description

get String in lines from InputStream

Demo Code


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

public class Main {
    public static String getString(InputStream in) throws IOException {

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(in));
        StringBuilder builder = new StringBuilder();
        String line;/*from  w w  w. jav a  2  s.c o  m*/
        while ((line = reader.readLine()) != null) {
            builder.append(line);
            builder.append(System.getProperty("line.separator"));
        }
        return builder.toString();
    }
}

Related Tutorials