android做json解析,从服务器获取资源

public static List<Model> getJSONResource(String path) throws Exception {
    URL url = new URL(path);
    HttpURLConnection connection = (HttpURLConnection)url.openConnection();
    connection.setConnectTimeout(5000);
    connection.setRequestMethod("GET");
    Log.v("radom","5");
    if (connection.getResponseCode() == 200) {
        InputStream inputStream = connection.getInputStream();
        Log.v("radom","2");
        return parserJSON(inputStream);
    }else{
        throw new RuntimeException("服务器响应失败");
    }
}

代码执行到InputStream那里,也就是创建输入流对象,就不执行了是什么原因阿?我用输出检测的,只输出5,不输出2。如果把if语句去掉,也还是不输出2

有if的时候执行服务器响应失败了吗

输出一下connection.getResponseCode()看看是不是值不等于200