I'm trying to scan String from my input stream, but it won't close. Here is my code:
public static String receive(int sid)
{
Scanner sc = new Scanner(servers[sid].getInputStream(), "UTF-8").useDelimiter("\\A");
String s = sc.next();
sc.close();
return s;
}
It's possible your program is getting stuck on this line:
String s = sc.next();
Have you tried using sc.hasNext() or sc.hasNextLine() to check for further data? Does the input data have an EOF character?
Also, this question may be of help: Java Scanner won't "finish" reading input
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.