Podcast
Questions and Answers
What is a stream in Java?
What is a stream in Java?
How does a stream deliver data?
How does a stream deliver data?
What is a code example of a stream?
What is a code example of a stream?
What are the two kinds of streams in Java?
What are the two kinds of streams in Java?
Signup and view all the answers
What do Byte Streams do?
What do Byte Streams do?
Signup and view all the answers
What do Character Streams do?
What do Character Streams do?
Signup and view all the answers
Why is buffering used in Java?
Why is buffering used in Java?
Signup and view all the answers
What is expensive in terms of accessing data?
What is expensive in terms of accessing data?
Signup and view all the answers
What is the purpose of the LineNumberReader?
What is the purpose of the LineNumberReader?
Signup and view all the answers
What is setLineNumber() used for in LineNumberReader?
What is setLineNumber() used for in LineNumberReader?
Signup and view all the answers
What is the purpose of the BufferedReader?
What is the purpose of the BufferedReader?
Signup and view all the answers
What is the purpose of the PrintWriter?
What is the purpose of the PrintWriter?
Signup and view all the answers
What is the default behavior of PrintWriter?
What is the default behavior of PrintWriter?
Signup and view all the answers
What can a PrintWriter wrap?
What can a PrintWriter wrap?
Signup and view all the answers
What is the purpose of the File class?
What is the purpose of the File class?
Signup and view all the answers
What is the purpose of the InputStreamReader?
What is the purpose of the InputStreamReader?
Signup and view all the answers
Study Notes
Streams
- A stream is an object that represents data being delivered to or from an object, one byte or character at a time.
- There are two kinds of streams: Byte Streams and Character Streams (also known as "readers" and "writers").
- Byte Streams read and write raw bytes, while Character Streams read and write characters (16-bit Unicode).
Readers and Writers
- Readers and Writers are Character Streams that read and write characters.
- Examples of Readers and Writers include FileReader, FileWriter, and PrintWriter.
Buffering
- Buffering is used to improve performance when accessing data outside of memory (e.g., disk, network, web).
- It is more efficient to access a large chunk of data at once rather than one byte or character at a time.
LineNumberReader
- A LineNumberReader is a buffered character-input stream that keeps track of line numbers.
- The setLineNumber() method does not seek to a line in the file, but rather designates the line number of the first line.
InputStreamReader and PrintWriter
- InputStreamReader converts bytes from an InputStream to characters, using the proper encoding.
- PrintWriter prints formatted representations of objects to a text-output stream.
- System.out is a PrintWriter.
Using Streams on the Web
- Streams can be used to read from a URL object, URLConnection object, and write to a URLConnection object or HttpServletResponse object.
File
- A File object is a wrapper for a String, and does not necessarily denote something on the file system.
- A File object can be created with any string, regardless of whether it's a valid filename or not.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about Java streams, readers, writers, buffers, and files. Understand the concept of streams, their behavior, and how they are used in Java I/O operations.