0% found this document useful (0 votes)
9 views14 pages

Institute: Uie Department: Cse: Bachelor of Engineering (Computer Science & Engineering)

The document presents a lecture on Object Oriented Programming using Java, focusing on the FilterWriter and FilterReader classes. It explains their purpose, constructors, and methods, providing code examples for better understanding. The session concludes with a quiz question related to the DataOutputStream class.

Uploaded by

Rohit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views14 pages

Institute: Uie Department: Cse: Bachelor of Engineering (Computer Science & Engineering)

The document presents a lecture on Object Oriented Programming using Java, focusing on the FilterWriter and FilterReader classes. It explains their purpose, constructors, and methods, providing code examples for better understanding. The session concludes with a quiz question related to the DataOutputStream class.

Uploaded by

Rohit Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

INSTITUTE : UIE

DEPARTMENT : CSE
Bachelor of Engineering (Computer Science &
Engineering)

Object Oriented Programming using Java


(23CSP-202 )
TOPIC OF PRESENTATION:
IOpackage Prepared by:
Bhavneet Kaur
Master Subject
Coordinator

DISCOVER . LEARN . EMPOWER


Lecture Objectives

In this lecture, we will discuss:


• FilterWriter and FilterReader

2
FilterWriter
Java FilterWriter class is an abstract class which is used to
write filtered character streams.
The sub class of the FilterWriter should override some of its
methods and it may provide additional methods and fields also.

Constructors
Modifier: protected
Constructor: FilterWriter(Writer out)
Description: It creates InputStream class Object

Filters or processes the characters


written to it, then writes the results to
the Writer it manages
Methods
Example
class FilterWriterDemo {
public static void main(String[] args) throws
Exception {
FilterWriter fr = null;
Writer wr = null;
wr = new StringWriter();
fr = new FilterWriter(wr) {} ;
String str = “Bhavneet";
char c[] = {‘B',’h',’a',’v'};
//illustrating write(String str,int off,int
len)
fr.write(str);
//illustrating flush()
fr.flush();
//illustrating write(char[] cff,int
off,int len)
fr.write(c);
//illustrating write(int c)
fr.write('s');
System.out.print(wr.toString());
//close the stream
fr.close();
}
}
FilterReader
The Java.io.FilterReader class is for
reading filtered character streams.

The class itself provides default methods


that pass all requests to the contained
stream.
The Subclasses of FilterReader should FilterReader selectivel
override some of these methods and may y processes the data
also provide additional methods and fields. obtained from
the Reader it manages
Class declaration

Following is the declaration for Java.io.FilterReader class



public abstract class FilterReader extends Reader

Class constructors

protected FilterReader(Reader in): This creates a new


filtered reader.
Java FilterReader class methods
Example
//Java program illustrating FilterReader class methods
import java.io.*;
class FilterReaderdemo {
public static void main(String[] args) throws
IOException {
Reader r = new StringReader(“Bhavneet");
FilterReader fr = new FilterReader(r) {
};
char ch[] = new char[8];

//illustrating markSupported()
if(fr.markSupported()) {
//illustrating mark() method
System.out.println("mark method is
supported");
fr.mark(100);
}
Example
//illustrating skip() method
fr.skip(5);
//illustrating ready()
if(fr.ready()) {
//illustrating read(char[] cbuff,int
off,int len)
fr.read(ch);
for (int i = 0; i < 8; i++) {
System.out.print(ch[i]);
}
//illustrating reset()
fr.reset();
for (int i = 0; i <5 ; i++) {
//illustrating read()

System.out.print((char)fr.read());
} }
//closing the stream
QUIZ:

What class is extended by DataOutputStream class?

a. FilterOutputStream
b. BufferedOutputStream
c. ByteArrayOutputStream
Summary:

In this session, you were able to :

•Learn about FilterWriter and FilterReader


THANK YOU

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy