Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Java.io.FilterInputStream Class in Java
Next article icon

Java.io.FilterWriter class in Java

Last Updated : 12 Sep, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Abstract class for writing filtered character streams. The abstract class FilterWriter itself provides default methods that pass all requests to the contained stream. Subclasses of FilterWriter should override some of these methods and may also provide additional methods and fields.
Constructor :

  • protected FilterWriter(Writer out) : Create a new filtered writer.

Methods :

  • void close() : Closes the stream, flushing it first.Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.
    Syntax :public void close()             throws IOException  Throws:  IOException 
  • void flush() : Flushes the stream.
    Syntax :public void flush()             throws IOException  Throws:  IOException
  • void write(char[] cbuf, int off, int len) : Writes a portion of an array of characters.
    Syntax :public void write(char[] cbuf,           int off,           int len)             throws IOException  Parameters:  cbuf - Buffer of characters to be written  off - Offset from which to start reading characters  len - Number of characters to be written  Throws:  IOException
  • void write(int c) : Writes a single character.
    Syntax :public void write(int c)             throws IOException  Parameters:  c - int specifying a character to be written  Throws:  IOException
  • void write(String str, int off, int len) : Writes a portion of a string.
    Syntax :public void write(String str,           int off,           int len)             throws IOException  Parameters:  str - String to be written  off - Offset from which to start reading characters  len - Number of characters to be written  Throws:  IOException 

Program :




//Java program demonstrating FilterWriter methods
import java.io.FilterWriter;
import java.io.StringWriter;
import java.io.Writer;
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 = "Geeksfor";
        char c[] = {'G','e','e','k'};
  
        //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();
    }
}
 
 

Output :

GeeksforGeeks


Next Article
Java.io.FilterInputStream Class in Java

N

Nishant Sharma
Improve
Article Tags :
  • Java
Practice Tags :
  • Java

Similar Reads

  • Java.io.FilterReader class in Java
    Abstract class for reading filtered character streams. The abstract class FilterReader itself provides default methods that pass all requests to the contained stream. Subclasses of FilterReader should override some of these methods and may also provide additional methods and fields. Constructor : pr
    3 min read
  • Java.io.FilterInputStream Class in Java
    Filter Streams filters data as they read and write data in the Input Stream, filters it and pass it on to the underlying Streams. Filter Streams are FilterInputStream FilterOutput Stream FilterInputStream : Java.io.FilterInputStream class works almost like InputStream class in Java but what it does
    9 min read
  • Java.io.FilterOutputStream Class in Java
    java.io.FilterInputStream Class in Java Java.io.FilterOutputStream class is the superclass of all those classes which filters output streams. The write() method of FilterOutputStream Class filters the data and write it to the underlying stream, filtering which is done depending on the Streams. Decla
    5 min read
  • Java FileWriter Class
    Java FileWriter class of the java.io package is used to write data in character form to a file. The FileWriter class in Java is used to write character-oriented data to a file. It is a character-oriented class that is used for file handling in Java. This Class inherits from OutputStreamWriter class
    5 min read
  • Java.io.Console class in Java
    The Java.io.Console class provides methods to access the character-based console device, if any, associated with the current Java virtual machine. The Console class was added to java.io by JDK 6. Important Points: It is used to read from and write to the console, if one exists. Console is primarily
    4 min read
  • java.nio.FloatBuffer Class in Java
    A Buffer object can be termed as a container for a fixed amount of data. The buffer acts as a storing box, or temporary staging area, where data can be stored and later retrieved according to the usage. Java Buffer classes are the foundation or base upon which java.nio is built. Float buffers are cr
    4 min read
  • Java.io.InputStream Class in Java
    Java InputStream class is the superclass of all the io classes i.e. representing an input stream of bytes. It represents an input stream of bytes. Applications that are defining a subclass of the Java InputStream class must provide a method, that returns the next byte of input. A reset() method is i
    3 min read
  • Java.io.Writer class in Java
    This abstract class for writing to character streams. The only methods that a subclass must implement are write(char[], int, int), flush(), and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.
    4 min read
  • Java.io.DataInputStream class in Java | Set 1
    A data input stream enables an application to read primitive Java data types from an underlying input stream in a machine-independent way(instead of raw bytes). That is why it is called DataInputStream - because it reads data (numbers) instead of just bytes.  An application uses a data output stream
    3 min read
  • Java.io.DataInputStream class in Java | Set 2
    Java.io.DataInputStream class in Java | Set 1 More Methods: byte readByte() : Reads and returns one input byte. Syntax:public final byte readByte() throws IOException Returns: the next byte of this input stream as a signed 8-bit byte. Throws: EOFException IOException float readFloat() : Reads four i
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences