InputStream to String

จาก Paween Khoenkaw

private StringBuilder inputStreamToString(InputStream is) {

String line = "";

StringBuilder total = new StringBuilder();

// Wrap a BufferedReader around the InputStream

BufferedReader rd = new BufferedReader(new InputStreamReader(is));

// Read response until the end

try {

while ((line = rd.readLine()) != null) {

total.append(line);

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// Return full string

return total;

}