get Input Stream Content - Java java.io

Java examples for java.io:InputStream Read

Description

get Input Stream Content

Demo Code


//package com.java2s;

import java.io.FileNotFoundException;

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

public class Main {
    public static String getInputStreamContent(InputStream stream)
            throws IOException {
        InputStreamReader in = null;
        StringBuffer buf = null;// w w w . j  av a2 s.  c  o m
        try {
            buf = new StringBuffer();
            in = new InputStreamReader(stream);
            int c;
            while ((c = in.read()) != -1) {
                buf.append((char) c);
            }
        } catch (FileNotFoundException fileNotFounfEx) {
            throw fileNotFounfEx;
        } catch (IOException ioEx) {
            throw ioEx;
        } finally {
            in.close();
        }

        return buf.toString();
    }
}

Related Tutorials