Java InputStream to String valueOf(InputStream is)

Here you can find the source of valueOf(InputStream is)

Description

value Of

License

Open Source License

Declaration

public static String valueOf(InputStream is) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String valueOf(InputStream is) {

        try {//from  w ww .  j a v  a  2s. co m
            int i = -1;
            byte[] b = new byte[1024 * 100];
            StringBuffer sb = new StringBuffer();
            while ((i = is.read(b)) != -1) {
                sb.append(new String(b, 0, i));
            }
            String content = sb.toString();
            return content;

        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. inputStreamToStringBuilder(final InputStream inputStream, final String charset)
  2. inputStreamToStringBuilder(InputStream in, int minimumCapacity)
  3. inputStreamToText(InputStream inputStream)
  4. loadText(InputStream in)
  5. loadTextFile(InputStream stream, String encoding, int maxSize, boolean finish)