public static File downloadFileTo(String urlString, String ext, File dir) throws IOException {
		
		InputStream in		= null;
		OutputStream out	= null;
		File file			= null;
		
		if (!dir.exists()) { // If the download directory does not exist, we create it.
			dir.mkdirs();
		}
		
		try {
			in = openURLStream(urlString, null);
			file = File.createTempFile("web", ext, dir); // Creates a new empty file.
				
			out = new FileOutputStream(file);

			byte[] buffer = new byte[2048];
			int length;

			// Copy every input into the output.
			while ((length = in.read(buffer, 0, 2048)) > 0) {
				out.write(buffer, 0, length);
			}
			
			Log.d("HTTPGet", "Download " + urlString + " to " + file.getAbsolutePath()); // Debug
			
		/*
		 * This catch/finally is because we need to log what happened in this class and because
		 * we need to close all streams (if we had thrown an exception without catching it, 
		 * we wouldn't have been able to close the streams properly).
		 */
		} catch (IOException e) { // Allows to close Streams
			
			Log.e("HTTPGet", "Error while downloading " + urlString + " to "
					+ file.getAbsolutePath() + "\n\t" + e.getMessage());
			
			throw e;
			
		} finally { // Closes all Streams
			
			if (in != null) in.close();
			if (out != null) out.close(); 
		}
		
		return file;
	}