Home  >  Article  >  Java  >  What is the importance of StringReader class in Java?

What is the importance of StringReader class in Java?

WBOY
WBOYforward
2023-09-11 08:49:02612browse

The

What is the importance of StringReader class in Java?

StringReader class is a subclass of the Reader class, which can be used to read characters from the stream Use string form as the source of StringReader. The StringReader class will override all methods in the Reader class. The important methods of the StringReader class include skip(), close(), mark(), markSupported(), reset(), etc.

Syntax

<strong>Public class StringReader extends Reader</strong>

Example

import java.io.StringReader;
import java.io.IOException;
public class StringReaderTest {
   public static void main(String[] args) {
      String str = "Welcome to Tutorials Point";
      StringReader strReader = new StringReader(str);
      try {
         int i;
         while((i=strReader.read()) != -1) {
            System.out.print((char)i);
         }
      } catch(IOException ioe) {
         System.out.println(ioe);
      } finally {
         if(strReader != null) {
            try {
               strReader.close();
            } catch(Exception e) {
               System.out.println(e);
            }
         }
      }
   }
}

Output

Welcome to Tutorials Point

The above is the detailed content of What is the importance of StringReader class in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete