关于java socket文件传输的问题...

刚接触socket的问题,下面代码中如果不加一个“Thread.sleep(1);”的话,图片文件或者视频文件的时候就有数据流失,哪位给看看,是不是概念还是其他什么的理解不对

socket = new Socket(ip,port);
PrintWriter out = new PrintWriter(socket.getOutputStream());
out.println(filename);
out.flush();

            dos = new DataOutputStream(socket.getOutputStream());
            File file = new File(path);
            dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
            byte[] sendbytes = new byte[1024];
            Thread.sleep(1);
            while (((length =dis.read(sendbytes))) > 0){
                dos.write(sendbytes, 0, length);
                dos.flush();
            } 

可参考:
http://blog.csdn.net/kongxx/article/details/7319410
http://blog.chinaunix.net/uid-25885064-id-3362396.html
http://blog.csdn.net/hzw2312/article/details/13291999
http://www.blogjava.net/sterning/archive/2007/10/13/152508.html