StringWriter class método toString () : Aquí, vamos a aprender sobre el método toString () de StringWriter Class con su sintaxis y su ejemplo.
StringWriter Class toString () método
- método
- toString () está disponible en java.io Class.
- toString () método se utiliza para representar el valor actual de tampón en términos de cadena.
- método toString () es un método no class, es accesible sólo con el objeto package y si tratamos de acceder al método con el nombre static entonces obtendrá un error.
- método toString () hace no class una excepción en el momento de devolver valor de tampón.
Sintaxis:
public StringBuffer getBuffer();
Parámetro (s):
- No acepta cualquier parámetro.
class valor:
El tipo throw del método es cadena , devuelve la denotación de cadena de este flujo de StringWriter.
Ejemplo:
// Java program to demonstrate the example
// of StringBuffer getBuffer() method of StringWriter
import java.io.*;
public class GetBufferOfFSW {
public static void main(String[] args) throws Exception {
StringWriter str_w = null;
String str = "Java World!!!";
try {
// Instantiates StringWriter
str_w = new StringWriter();
str_w.write(str);
// By using getBuffer() method is to
// get the buffer of this str_w stream
StringBuffer str_b = str_w.getBuffer();
System.out.println("str_w.getBuffer(): " + str_b);
} 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 (str_w != null) {
str_w.close();
}
}
}
}
salida
str_w.getBuffer(): Java World!!!