I am trying to download a pdf file on this url: http://hitbullseye.com/includes/testmaster_pdffiles/CAT 2013.pdf using the following code:
URL url = new URL("http://hitbullseye.com/includes/testmaster_pdffiles/CAT%202013.pdf");
URLConnection ucon = url.openConnection();
ucon.setReadTimeout(40000);
ucon.setConnectTimeout(40000);
InputStream is = ucon.getInputStream();
It is throwing FileNotFound Exception at InputStream is = ucon.getInputStream(); I have given Internet permission in my manifest. I am downloading other files too, but this one is not downloading.
My Logcat:
06-12 15:59:50.091: E/Note:(28745): file url: http://hitbullseye.com/includes/testmaster_pdffiles/CAT%202013.pdf
06-12 15:59:50.251: D/libc(28745): [NET] getaddrinfo hn 19, servname NULL, ai_family 0+
06-12 15:59:50.251: D/libc(28745): [SMD][Mode1]: Screen on and original TTL is not expired,bl_level=131
06-12 15:59:50.251: D/libc(28745): FOUND IN CACHE entry=0x52788a30
06-12 15:59:50.541: W/System.err(28745): java.io.FileNotFoundException: http://www.hitbullseye.com/includes/testmaster_pdffiles/CAT 2013.pdf
06-12 15:59:50.551: W/System.err(28745): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
I encoded the url also by following code:
URI urii;
try {
urll = new URL(downloadUrl);
urii = new URI(urll.getProtocol(), urll.getUserInfo(),
urll.getHost(), urll.getPort(), urll.getPath(),
urll.getQuery(), urll.getRef());
urll = urii.toURL();
downloadUrl = urll.toString();
} catch (Exception e1) {
e1.printStackTrace();
}
I am not posting any duplicate question. I already read HTTP URL Address Encoding in Java, but I guess its some different issue. Please help! Even DownloadManager is not downloading it, returning HTTP_DATA_ERROR.