我在我的套接字代码中嵌套了 while 循环。这很糟糕吗?有一个更好的方法吗?
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();
}
}