Note that there are some explanatory texts on larger screens.

plurals
  1. PODownloading images through socket or http
    primarykey
    data
    text
    <p>I have custom socket client server. Now when I transfer binary files, some bytes convert onto out of range characters. So I send them in hex string. That works. But for another problem this is not the solution.</p> <p>When I download images from the net, same thing happens. Some bytes change into something else. I have compared bytes by bytes. Converting into String show ? instead of the symbol. I have tried readers and byte array input stream. I have tried all the examples on the net. What is the mistake I could be doing?</p> <p>update (answer accepted):</p> <p>Check the mime of the object you send or receive. If it is a binary file, use the InputStream | OutputStream and derived classes, when text, use Reader | Writer and derived classes.</p> <p>Do not use the Readers and Writers to download a binary file, like I did (this only works for the text, and then you have to use hex string that adds to performance problems):</p> <pre><code>void saveFile(String strFileName){ try{ URL url = new URL(strImageRoot + strFileName); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); BufferedWriter bw = new BufferedWriter(new FileWriter(strImageDownloadPath + strFileName)); String line = null; while ( (line = reader.readLine()) != null) { bw.write(line); } }catch(FileNotFoundException fnfe){ System.out.println("FileNotFoundException occured!!!"); }catch(IOException ioe){ }catch(Exception e){ System.out.println("Exception occured : " + e); }finally{ System.out.println("Image downloaded!!!"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload