Home » Java programming language

Java FilterReader skip() Method with Example

FilterReader Class skip() method: Here, we are going to learn about the skip() method of FilterReader Class with its syntax and example.
Submitted by Preeti Jain, on April 03, 2020

FilterReader Class skip() method

  • skip() method is available in java.io package.
  • skip() method is used to skip the given number of characters from this FilterReader.
  • skip() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • skip() method may throw an exception at the time of skipping characters.
    IOException: This exception may throw when getting any input/output error.

Syntax:

    public long skip(long number);

Parameter(s):

  • long number – represents the number of characters to be skipped.

Return value:

The return type of the method is long, it returns the exact number of characters skipped.

Example:

// Java program to demonstrate the example 
// of long skip(long number) method of FilterReader

import java.io.*;

public class SkipOfFR {
 public static void main(String[] args) throws Exception {
  Reader r_stm = null;
  FilterReader fr_stm = null;

  try {
   // Instantiates StringReader and 
   // FilterReader
   r_stm = new StringReader("Java World!!!!");
   fr_stm = new FilterReader(r_stm) {};

   // Loop to read until available
   // bytes left
   for (int val = 0; val <= 6; ++val) {

    // Read corresponding char value
    char ch = (char) fr_stm.read();

    // Display value of ch
    System.out.println("ch: " + ch + " ");

    // By using skip() method is
    // to skip 1 bytes of char 
    // from fr_stm	    
    long skip = fr_stm.skip(1);
    System.out.println("fr_stm.skip(1): " + skip);
   }
  } catch (Exception ex) {
   System.out.println(ex.toString());

  } finally {
   // with the help of this block is to
   // free all necessary resources linked
   // with the stream
   if (fr_stm != null) {
    fr_stm.close();
   }
  }
 }
}

Output

ch: J 
fr_stm.skip(1): 1
ch: v 
fr_stm.skip(1): 1
ch:   
fr_stm.skip(1): 1
ch: o 
fr_stm.skip(1): 1
ch: l 
fr_stm.skip(1): 1
ch: ! 
fr_stm.skip(1): 1
ch: ! 
fr_stm.skip(1): 1





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.