server sends file to clients java
<p>I have a server and multiple clients and i am trying to make the server-thread send a file to the all connected clients at the same time.The weird thing is,sometimes the files are written correctly and sometimes the laptop makes noise and the files are written in the console and no files are created.I don`t do any changes in the code between the trials.Could anyone help me about that? Thanks in advance.Here is the sending server-thread code</p>

<pre><code>try
{   
    out.println("AcceptFile,");
    FileInputStream fis = new FileInputStream(fn);
    byte[] buffer = new byte[fis.available()];
    fis.read(buffer);
    ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream()) ;
    oos.writeObject(buffer);
    oos.flush();
}
catch(Exception c)
{
    System.err.println("exc" + c);
}
</code></pre>

<p>Here is the Client-thread receiving</p>

<pre><code>try
{
    ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                    byte[] buffer = (byte[])ois.readObject();
                    String pic="copy"+studId+".pdf";
                    System.out.println(pic);
                    FileOutputStream fos = new FileOutputStream(pic);
                    fos.write(buffer);  
                    fos.flush();
                    fos.close();    
}
catch(Exception e)
{
    System.out.println("Exception writing");
}
</code></pre>
