工具类:处理网络请求的回应

    public class StreamUtils {

    public static String convertStream2Str(InputStream input){

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int len = -1;
        byte[] buffer = new byte[512];
        try {
            while((len=input.read(buffer)) != -1){
                baos.write(buffer, 0, len);
                return new String(baos.toByteArray());
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;

    }
}

你可能感兴趣的:(安卓开发之旅)