0

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;

}
Charles
  • 50,943
  • 13
  • 104
  • 142

1 Answers1

2

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

Community
  • 1
  • 1
Danny
  • 705
  • 1
  • 7
  • 23