Problem with server send file to client
<p>I have trying to make the server send a file to the all connected clients,i have many codes,but sometimes the computer makes noise and the files are written to the console so i was encouraged to use DataOutputStream,but getting some problems,the files are created but they are empty.Could anyone please help me about that? Here is the server-thread sending code:</p>

<pre><code>        out.println("AcceptFile,");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject((Object)fn);

        byte[] bytes = bos.toByteArray();

        FileOutputStream fos = new FileOutputStream(fn);
    //  DataOutputStream dos = new DataOutputStream(fos);

        DataOutputStream dos = new DataOutputStream(socket.getOutputStream());

        // header
        dos.writeInt(bytes.length);
        for (int i = 0; i &lt; bytes.length; i++) 
        {
             dos.write(bytes[i]); 
        }
        dos.flush();`
</code></pre>

<p>Here is the Client-receiving code:</p>

<pre><code>                String pic="copy"+studId+".pdf";
                System.out.println(pic);
                FileOutputStream fos = new FileOutputStream(pic);
                DataInputStream dis = new DataInputStream(socket.getInputStream());

                System.out.println("inside try send");
                int numToRead = dis.readInt();
                byte[] bytes =  new byte[numToRead]; 
                dis.readFully(bytes);

                ByteArrayInputStream bis = new ByteArrayInputStream(bytes);

                ObjectInputStream ois = new ObjectInputStream(bis);

                ois.readObject();

                for (int i = 0; i &lt; bytes.length; i++) 
                {
                     fos.write(bytes[i]);   
                }

                fos.flush();
                fos.close();
</code></pre>
