如何使用扫描仪检查行尾?

如何使用扫描仪检查行尾?,第1张

如何使用扫描仪检查行尾?

考虑使用多个扫描仪,一个扫描仪获取每一行,另一扫描仪扫描每行。我唯一要说明的是,使用完内部扫描仪后,请务必确保将其关闭。实际上,使用完 所有
扫描仪后,您将需要关闭它们,但特别是内部扫描仪,因为它们会增加和浪费资源。

例如,

Scanner fileScanner = new Scanner(myFile);while (fileScanner.hasNextLine()) {  String line = fileScanner.nextLine();  Scanner lineScanner = new Scanner(line);  while (lineScanner.hasNext()) {    String token = lineScanner.next();    // do whatever needs to be done with token  }  lineScanner.close();  // you're at the end of the line here. Do what you have to do.}fileScanner.close();


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5616069.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存