Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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

public class Main {

    public static String inputStreamToString(InputStream inputStream) {
        if (inputStream == null) {
            System.out.println("InputStream is null");
            return null;
        }

        try {
            int i = -1;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            while ((i = inputStream.read()) != -1) {
                baos.write(i);
            }
            String content = baos.toString();
            return content;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}