I am trying to download a file using HTTP. Text files and HTML files are getting downloaded perfectly, but not any other files. I refered Complete Reference Java 2, I found that MIME Header has something to do with this, but was not clear. So can any 1 help me in this regard. Thanx in advance, Tejas
I presume you are using text based input streams to download text and html files. If u want to read binary files like images,zip,exe files etc. use a binary stream. A code like this will help you. int a; URL url = new URL("http://www.abc.com/abc.jpg"); URLConnection urlConnection = url.openConnection(); InputStream i = urlConnection.getInputStream(); FileOutputStream fos = new FileOutputStream("abc.jpg"); while((a=i.read())) { fos.write(a); }
Thanx vgauri, Logically speaking reading in byte arrays should be the solution, but the thing is that for HTTP download, this does not really works. When we send the request we need to specify the MIME type, to download the image files. And this is what I don't know how to do it. The solution that you have given , that i have already tried. It does not help. Does any body know anything about the MIME header types ??? Thanx anyway V
You shouldn't have to specify anything different when downloading an image file. What you are permitted to do is check the mime-type the server reports that the file is. Some programs (internet explorer jumps to mind) ignore the mime-type and use only the file extension to distinguish jpeg's from gif's from tiff's. The mime-type is just another way of distinguishing file types.
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, the permaculture playing cards