Code example for URLConnection

Methods: connect, getContentLength

0
    private InputStream getFileFromRemoteServer(String remoteZipName) {
	URL url;
	try { 
	    url = new URL(remoteZipName);
	    URLConnection connexion = url.openConnection();
	    connexion.connect();
 
	    int lenghtOfFile = connexion.getContentLength();
	    Log.d(TAG, String.format(
		    "Download file named: %s\nLength of file: %d", 
		    remoteZipName, lenghtOfFile));
 
	    return new BufferedInputStream(url.openStream());
	} catch (Exception e) {
	    e.printStackTrace();
	} 
	return null; 
    } 
 
    /** 
     * @deprecated Cette fonction plante en test local (emulation) si internet