If I have a method that takes a reader and I want to operate on the reader with a Scanner like so:
Scanner scanner = new Scanner(reader);
while(scanner.hasNext()) {
//blah blah blah
}
Is it safe not to close scanner
? Documentation says that it "closes this scanner" and then talks about closing the underlying readable. Suppose I don't want to close the readable and instead want the caller to close reader
when ready. Is it safe not to close scanner
here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…