I am trying to download an EXE file from my website. So just for example, I went ahead to rarlab's site, and downloaded my self a fresh install of their 64 bit WinRAR release (we all know what that is.)
Anyways, I uploaded the 64 bit "setup" exe file to my root folder of my site where it is easily reachable to download (for testing purposes.) Going on my site through any browser I can successfully download the "setup" file from rarlabs AND execute it like any other EXE file.
Now, this is the confusing part I cannot for the love of God figure out. Using this simple code, that I ripped of some other Stack Overflow answer, I can download any EXE file from a given URL.
The code...
public static void downloadEXE(URL url, String file) throws IOException {
InputStream in = url.openStream();
FileOutputStream fos = new FileOutputStream(new File(file));
int length = -1;
byte[] buffer = new byte[1024];// buffer for portion of data from
// connection
while ((length = in.read(buffer)) > -1) {
fos.write(buffer, 0, length);
}
fos.close();
in.close();
}
Where the URL and FILE arguments are...
URL url = new URL("http://www.website.com/winrar-x64-540.exe");
String file = "c:\\Users\\..\\Documents\\winrar-x64-540.exe";
Yes, this downloads the file from my site into my documents folder without any errors, but when I run it I get this error...
Not stopping there, I decided to try using this same exact code to download the same 64 bit EXE "setup" file EXCEPT this time from the official site, rarlabs. You can take my word for it I used the correct URL, because this time I not only downloaded the EXE file using this code, but also was able to successfully run it!
Leaving me to suspect there is something wrong with my site, not the EXE file? I should also mention a very IMPORTANT discovery I found that will most likely help. I decided to compare the properties from the WORKING EXE file with the BROKEN diseased one. The size of the working one was 2.07 MB whilst the broken one was a whopping 375 bytes! The broken exe didn't match the properties the working exe had AT ALL.
Seeing the comparison of the two files leaves my thinking that my site is not at fault, as I am able to download and launch my file successfully through any browser, but the code is at error.
Please ask me any questions you need to figure out the problem. Let me know where I need to be specific. Thanks all. :)