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

What is the importance of StringReader class in Java?

WBOY
Release: 2023-09-11 08:49:02
forward
677 people have browsed it

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>
Copy after login

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);
            }
         }
      }
   }
}
Copy after login

Output

Welcome to Tutorials Point
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template