English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Importanza della classe StringReader in Java?

StringReader La classe è una sottoclasse dilettore La classe, che può essere utilizzata per leggerecaratteri flussoè una stringa che rappresenta la fonte StringReader. LaStringReader La classe coprerà tutti i metodi della classe lettore. I metodi importanti di StringReadersaltare()(), , close(),,mark()markSupported()reset() ecc.

Sintassi

Public class StringReader extends Reader

Esempio

import java.io.StringReader;
import java.io.IOException;
public class StringReaderTest {
   public static void main(String[] args) {
      String str = "Welcome to oldtoolbag.com";
      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);
            }
         }
      }
   }
}

Risultato di output

Benvenuti su oldtoolbag.com