Q:

nested while loops in sockets code, is this ok?

i have nested while loops in my sockets code.  is this bad?  is there a better way to do this?
     if(socket!=null){
     try {

           output = new FileOutputStream("/mnt/sdcard/testdatabase.db");

           byte[] buffer = new byte[1024];
           int length;
     while(connected){

           input = (FileInputStream) socket.getInputStream();

           while((length = input.read(buffer))>0){
               output.write(buffer, 0, length);

           } // end inner while

      } // end outer while

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

   }

A:

It doesn't look like the outer while is useful - you can just remove it.
The inner while should continue until EOF, or an error.

