The
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.
<strong>Public class StringReader extends Reader</strong>
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); } } } } }
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!