BREAKING:

[HowTo] Android – InputStream to String Conversion

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

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

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