简体   繁体   中英

Java method println being skipped

//  out.println(" ");//solution
    for (Utilizador ut : Diretorio.getInstance().getUtilizadores()) {
     String s = ("CLT " + ut.getEndereco() + " " +  ut.getPorto() );
        out.println(s); 
        }
    out.println("END");
    System.out.println("Consulta realizada");

So i send this to my out stream, but then in my "in" stream i only receive "END" (if the list only has 1 object) if the list has 2 objects my "in" stream will show only 1 object and then END Here is my "in"

} else if(in.readLine()!=null){
   while((msg = in.readLine())!= null){                      
    System.out.println(msg);
   }
 } 

Cant understand why one of my "out.println()" is being skipped or simply not shown Both classes are Threads

in this code

} else if(in.readLine()!=null){
   while((msg = in.readLine())!= null){                      
       System.out.println(msg);
   }
}

when if(in.readLine()!=null) is executed a line is read but not printed and then in the while loop every msg = in.readLine() reads another line and print it.
But the 1st line is never printed.
Change it to:

} else {
   while((msg = in.readLine())!= null){                      
       System.out.println(msg);
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM