Scanner 클래스는 nextLine()으로 한 줄을 읽어올 때 그 값이 null이면 null을 리턴하는 게 아니라
noSuchElementException을 반환하네요.
BufferedReader을 사용하면 될 것 같습니다.
엔터로 종료하는 게 아니라 EOF를 발생시키면 해당 Exception이 발생합니다.
public String nextLine() {
if (hasNextPattern == linePattern())
return getCachedResult();
clearCaches();
String result = findWithinHorizon(linePattern, 0);
if (result == null)
throw new NoSuchElementException("No line found");
MatchResult mr = this.match();
String lineSep = mr.group(1);
if (lineSep != null)
result = result.substring(0, result.length() - lineSep.length());
if (result == null)
throw new NoSuchElementException();
else
return result;
}
baekjc94 3년 전
제가이해한대로는 맞게 결과가 나오는거같는데 오류라고 뜨네요