Java http download corrupts file -


I have a problem, which does not seem to be able to solve me ... I download an http of a file, But the CRC 32 does not match the file on the server and on the client. Besides, the size of the file is different, so I have to mess something ... When I download via Firefox, the filesystem is ok ... then I think this client is somewhere in the code.

I have already found it, but he did not even help me ...

Here is the code:

  Private Zero Download Jar ( String filename, long CRC32 server) throws IOException {system .out.println ("downloading file" "" + "'+ + mServer +"' '"+" file name) ";); HttpURL connection source connection = zero; BufferedInputStream inputstream = Faucet; Buffdater file file = null; Long crc32 client; {URL sourceURL = Try new URL (filename); {SourceConnection = (HttpURLConnection) try sourceURL.openConnection (); } Catch (Malmandurulipation Act) {New Runtime Expansion ("Configurable URL has created a malurfordae explanation:", ach); } SourceConnection.setRequestProperty ("accept-encoding", "zip, jar"); SourceConnection.connect (); Inputstream = new BufferedInputStream (sourceConnection.getInputStream ()); FileWriter = New buffed vetter (new Flemerer (Targetfolder + File. Separator + Filename)); CRC 32 CRC 32 = New CRC 32 (); (Int singlebeat = inputstream.read (); singlebyte! = -1; singlebit = inputstream.read ()) {fileWriter.write (singlet); Crc32.update (singleByte); } Crc32Client = crc32.getValue (); } Finally {if (inputstream! = Null) {inputStream.close (); } If (fileWriter! = Null) {fileWriter.flush (); FileWriter.close (); } If (sourceConnection! = Null) {sourceConnection.disconnect (); }} If (crc32client! = Crc32 server) {// deleteFile (fileName); New IOException Throw ("Mail Not Ceased for CRC 32 File" "+ fileName +" ': "+ crc32client +"! = "+ Crc32 server);}}  
< P>

You should use one instead of /, in general, * stream handles raw binary data, while < Code> * Writers handle character data (which is the interpretation of raw binary data for a given character encoding).


Comments