【发布时间】:2014-05-31 10:27:29
【问题描述】:
我正在尝试从带有空格的扫描仪中读取,我什至想读取空格。 例如,将“john smith”读作“john smith”。
我的代码如下: 当它在 john 之后到达空间时,它只是挂起并且不再读取。 任何帮助将不胜感激。
Scanner in = new Scanner(new InputStreamReader(sock.getInputStream()));
String userName = "";
while (in.hasNext()) {
userName.concat(in.next());
}
【问题讨论】:
-
为什么你不使用
scanner.nextLine();我的意思是in.nextLine();
标签: java