Mega Code Archive

 
Categories / Android / File
 

Stream To String

import java.io.ByteArrayOutputStream; import java.io.InputStream; class Main {   public static String streamToString(InputStream is) {     ByteArrayOutputStream baos = new ByteArrayOutputStream();     int i = -1;     try {       byte[] bytes = new byte[1024];       while ((i = is.read(bytes)) != -1) {         baos.write(bytes, 0, i);         bytes = new byte[1024];       }       return new String(baos.toByteArray(), "UTF-8");     } catch (Exception e) {     }     return "";   } }