do not download the file conplete
===

i try to download a file using socket not url.. with the following code the file is not 
completely downloaded and when i try to open the file it show 
the message that the selected file could not be open...  this error can be removed by using 
url.openconnection() methods but  it need to be done through socket.... need suggestion ???


public class Check {

    private String addres;
    
    

    public void FileDownload(String urladd) {
        try {
            this.addres=urladd;
            
            
       
            String address;
            URL url_of_file=new URL(addres);
            String hostaddress=url_of_file.getHost();
            Socket mysocket=new Socket(hostaddress, 80);
            System.out.println("Socket opened to " + hostaddress + "\n");
            String file=url_of_file.getFile();
            System.out.println(" file = "+file);
            
            
            OutputStream os = mysocket.getOutputStream();
           
            os.write(("GET " + file + " HTTP/1.0\r\n").getBytes("UTF-8"));
            os.write(("HOST: " + hostaddress + "\r\n").getBytes("UTF-8"));
            os.write(("\r\n").getBytes("UTF-8"));
            os.flush();
          

           String url = "C:\\Users\\Desktop\\file_downloaded.jpg";
           File f=new File(url);
           f.createNewFile();
           
            OutputStream ops = new FileOutputStream(f);
            
            byte data = 0;
            InputStream in=mysocket.getInputStream();
            
          
            
            data = (byte) in.read();
            while (data != -1) {
                ops.write(data);
                data = (byte) in.read();
            }
            ops.flush();
            ops.close();
            mysocket.close();
            
            