방금 Java에서 I/O로 시작했고 내 의심이 어리석은 경우 실례합니다.하지만이 코드의 작동 방식을 이해하는 것이 어렵다고 생각하십니까? 아래 코드에서 변수 c가 증가하지 않으면 입력 스트림에 하나의 문자 만 있어도 while 루프가 종료되지 않고 출력 스트림이 한 문자 만 계속 채워지지만이 코드는 실제로 만족스럽게 작동합니다. 그 이유는 무엇입니까?이 코드는 어떻게 작동합니까?
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyBytes {
public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("xanadu.txt");
out = new FileOutputStream("outagain.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
저와 같은 의심이 있습니까? :) [스트리밍하는 동안 버퍼 바이트 배열을 계속 채우는 방법?] (http://stackoverflow.com/questions/18105971/how-the-buffer-byte-array-is-continuously-filling-while-streaming) –