1
나는에서 File.getText()
방법을 사용하는 경우 그루비Groovy File.getText() - 닫아야합니까?
newFile().text
또는 newFile().getText()
내가 사용 된 파일 리더를 닫 일부 폐쇄 문을 실행해야 또는 방법은 그 자체로 할 것입니까?
나는에서 File.getText()
방법을 사용하는 경우 그루비Groovy File.getText() - 닫아야합니까?
newFile().text
또는 newFile().getText()
내가 사용 된 파일 리더를 닫 일부 폐쇄 문을 실행해야 또는 방법은 그 자체로 할 것입니까?
자체로 처리합니다. 호출
new File('a.txt').text
will callResourceGroovyMethods.getText(File)
public static String getText(File file, String charset) throws IOException {
return IOGroovyMethods.getText(newReader(file, charset));
}
어떤 당신이 callsIOGroovyMethods.getText(BufferedReader)
볼 수 있습니다 :
public static String getText(BufferedReader reader) throws IOException {
StringBuilder answer = new StringBuilder();
// reading the content of the file within a char buffer
// allow to keep the correct line endings
char[] charBuffer = new char[8192];
int nbCharRead /* = 0*/;
try {
while ((nbCharRead = reader.read(charBuffer)) != -1) {
// appends buffer
answer.append(charBuffer, 0, nbCharRead);
}
Reader temp = reader;
reader = null;
temp.close();
} finally {
closeWithWarning(reader);
}
return answer.toString();
}
당신이 볼 수 있듯이, 리더를 폐쇄을