Code example for URLConnection

Methods: getContentEncodinggetInputStream

   * Retrieve the contents named by {@code path} from the server. Throws 
   * {@link IOException} if an error occurred. 
  String getContentsFromServer(String path) throws IOException {
    URLConnection urlConnection = conn.getConnection(baseUrl + path);
    return inputStreamToString(urlConnection.getInputStream(), urlConnection.getContentEncoding());
   * Download a zip file from the server, unzip it into local files 
   * and return a list of pairs of names <zip file name, local name>. 
  Map<String, String> downloadZipFromServer(String assetsPath) throws IOException {
    HttpURLConnection httpUrlConn = conn.getConnection(baseUrl + assetsPath);
    int response = httpUrlConn.getResponseCode();
    if (response == HttpURLConnection.HTTP_NO_CONTENT) {
      System.out.println("No zip file from server. Returning empty file map.");
      return new HashMap<String, String>();
    } else if (response != HttpURLConnection.HTTP_OK) {
      throw new IOException("HTTP request for URL " + baseUrl + assetsPath +
Contextual code suggestions in your IDE  Get Codota for Java