[HowTo] Android – InputStream to String Conversion

By -

Many times we require to convert the InputStream to String value. Here is the Snippet which is used to convert the InputStream into the String.

public String iStreamToString(InputStream is1)
{
	 BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
	 String line;
	 StringBuilder sb =  new StringBuilder();
	 try {
		while ((line = rd.readLine()) != null) {
		 		sb.append(line);
		 }
		 rd.close();

	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	 String contentOfMyInputStream = sb.toString();
	 return contentOfMyInputStream;
}
Paresh Mayani

Lazy android developer, exploring the horizon of android development since 7 years, currently working as a Technical Lead - Android at Simform Solutions, India. Former Application Architect at KarConnect. He is the Head/Organizer of Google Developers Group (GDG), Ahmedabad

Loading Facebook Comments ...
Loading Disqus Comments ...