When attempting a .gif download from an URL address with an http protocol, the file is the right size, however the image is not loadable when viewing in a windows appliaction. Below is a bit of the sample code being used:
HttpURLConnection imgConnection = (HttpURLConnection fileName.openConnection(); // filename being the http URL
imgConnection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)");
InputStreamReader fileIn = new InputStreamReader(imgConnection.getInputStream());
FileWriter fileOut = new FileWriter(newName); // newName being client side filename
int c = 0;
while ((c = fileIn.read()) != -1) {
fileOut.write(c);
}
fileOut.flush();
fileOut.close();
fileIn.close();
Is there a better way? Maybe some kind of URL Encoding issue? Please help.


Reply With Quote

Bookmarks