The course is part of this learning path
In this course, we'll learn about the Java Input/Output subject.
- API and Java I/O
- OutputStream Class
- InputStream Class
- Reader Class
- Writer Class
- Serialization, Deserialization, and Non-Serializable objects
- Anyone looking to get Oracle Java Certification
- Those who want to learn the Java Programming language from scratch
- Java developers who want to increase their knowledge
- Beginners with no previous coding experience in Java programming
- Those who want to learn tips and tricks in Oracle Certified Associate – Java SE 8 Programmer certification exams
- No prior knowledge is required about the Java programming language
- Basic computer knowledge
Hi there, in this lesson, we'll talk about the Reader Class. In our previous lessons, we learned the InputStream class. Thanks to the InputStream class, we're able to read the data from the file as byte-based. The Reader class is also used to read data from the file, but the main difference is that the data is transported as characters, not bytes. This class is also included in the java.io package and is an abstract class. Since it's an abstract class, we cannot create objects directly from this class, we use subclasses for this. The well-known sub classes of the reader class are: FileReader, BufferedReader, InputStreamReader, LineNumberReader, CharArrayReader etc. Now let's look at the methods we use in the Reader class.
The Reader class provides different methods that are implemented by its subclasses. Here are some of the commonly used methods. The parameter list read method is used to read characters from streams. The read method with a parameter reads the characters from the stream and stores them in the specified array. The read method with three parameters reads the number of characters equal to the length of the stream and stores it in the specified array starting from the start. These methods return -1 if there is no data to read. Another method is the ready method. This method checks if the reader is ready to be read. If it is ready, return true else return false. Another method is the skip method.
This method discards the specified number of characters from the stream. Another method is the mark method. This method marks the position in the stream up to which the data has been read. Another method is the reset method. This method returns the control to the point in the stream where the mark is set. And lastly, the close method. This method closes the reader and releases any system resources associated with the stream. Thus, it increases the system efficiency. Yes, now let's take a short break here. In the next video, we'll do some exercises. See you in the next lesson.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.