Java I/O StreamsLesson 55Free preview
Java FileInputStream
This lesson is part of Java · All levels
Summary
FileInputStream is a stream of bytes that reads the contents of a file from start to finish. You can call read() for one byte or read(byte[]) to read at once into the buffer. The return value of -1 indicates that there is no more data to read.
Key points
- The constructor receives the name of the file (String) or object File
- Read() without an argument returns the byte value 0-255, or -1 at the end of the file
- Read(byte[] b) fill the array and return the number of bytes that were read
- Fill in some arrays for more detailed controls
- Including checked IOException and mandatory closure, most practically with try-with-resources
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.