강의

멘토링

커뮤니티

Inflearn Community Q&A

sye7158695's profile image
sye7158695

asked

Mastering Java Basics with Teacher Eun-jong (Do it! Introduction to Java Programming) - Part 2 (Master Edition)

Various auxiliary stream classes

여러 가지 보조 스트림 클래스들

Written on

·

307

0

여러가지 보조 스트림 클래스들 강의에서 BufferedInputStream과 BufferedOutputStream 예제에 왜 while( ( i = bis.read()) != -1){ bos.write(i); }

-1로 두는지 잘 이해가 되지 않습니다

java객체지향알고리즘

Answer 1

1

eunjong님의 프로필 이미지
eunjong
Instructor

InputStream은 1바이트를 읽는데 0-255까지의 값이 됩니다. 이때 파일의 끝이나 더이상 읽을 데이터가 없는경우 혹은 오류가 난 경우에는 -1을 반환합니다. 따라서 이 예제에서는 -1이 반환될때까지 읽게됩니다. 아래 javadoc을 참고하기시 바랍니다. image

sye7158695's profile image
sye7158695

asked

Ask a question