【急】一个关于network的问题
Waiting for clients to connect . . .
Client connected.
Exception in thread "Thread-0"
java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at Pieces20Service.doService(Pieces20Service.java:37)
at Pieces20Service.run(Pieces20Service.java:20)
at java.lang.Thread.run(Unknown Source)
前两行是提示的连接成功(通过ServerSocket和Socket)
但是连接成功了以后就出现了这个..
请问这是怎么回事,如何处理?
------解决方案--------------------
已经没有数据可以给你读取了。。。所以就抛异常了,可以在读取之前检测下:
while (sc.hasNext()) {
String str = sc.next();
System.out.println(str);
}