Chapter 9
Streams
Objectives:
After completing the chapter, you can:
- create, modify and delete files and folders, using the class File;
- write bytes to a file and read them back from the file, using FileOutputStreamandFileInputStream;
- write text data to a file and read them back from the file, using OutputStreamWriterandInputStreamReader;
- write text data to a file and read them back from the buffer, using BufferedOutputStreamandBufferedInputStream;
- write values of primitive data types to a file and read them back from the file, using DataOutputStreamandDataInputStream.
Streams are used together with exceptions. Exceptions will be explained in details next week. Hereof, please add into the methods' signature the following two words - throws Exception.
Topics
- 9.1 Introduction
- 9.2 Byte streams
- 9.3 Character streams
- 9.4 Buffered streams
- 9.5 Data streams
- 9.6 Some tricks with streams
- 9.7 Tasks
Cheat sheet
Alternative materials
- in English: H. Schildt. Java - The Complete Reference: Chapter: 13
- in Estonian: here
- in Russian: Г. Шилдт. Java 8. Полное руководство: Chapter: 13