이것은 당신이하고자하는 일에 논리를 적용하는 방법과 같습니다. 예를 들어 위의 예 단지 확인 보호 -1 확인 readChar 그의
private String readLine(InputStreamReader reader) throws IOException {
// Test whether the end of file has been reached. If so, return null.
int readChar = reader.read();
if (readChar == -1) {
return null;
}else{
StringBuffer string = new StringBuffer("");
// Read until end of file or new line
while (readChar != '\n') {
// Append the read character to the string. Some operating systems
// such as Microsoft Windows prepend newline character ('\n') with
// carriage return ('\r'). This is part of the newline character
// and therefore an exception that should not be appended to the
// string.
string.append((char)readChar);
// Read the next character
readChar = reader.read();
}
return string.toString();
}
}
그래서 이전 코드 샘플과 같이 기록되어 있었다.