Método Writer write(int) en Java con ejemplos

El método write(int) de Writer Class en Java se usa para escribir el valor de byte especificado en el escritor. Este valor de byte se especifica usando el valor ASCII del valor de byte pasado como un valor entero. Este valor entero se toma como parámetro.

Sintaxis:

public void write(int ascii)

Parámetros: este método acepta un parámetro obligatorio ascii que es el valor ASCII del valor del byte que se escribirá en el escritor.

Valor devuelto: este método no devuelve ningún valor.

Los siguientes métodos ilustran el funcionamiento del método write(int):

Programa 1:

// Java program to demonstrate
// Writer write(int) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a Writer instance
            Writer writer
                = new PrintWriter(System.out);
  
            // Write the byte value '0' to this writer
            // using write() method
            // This will put the string in the writer
            // till it is printed on the console
            writer.write(48);
  
            writer.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

0

Programa 2:

// Java program to demonstrate
// Writer write(int) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a Writer instance
            Writer writer
                = new PrintWriter(System.out);
  
            // Write the byte value 'A' to this writer
            // using write() method
            // This will put the string in the writer
            // till it is printed on the console
            writer.write(65);
  
            writer.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

A

Publicación traducida automáticamente

Artículo escrito por Code_r y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *