Java Writer write(int)方法及实例
Java中Writer类的write(int)方法是用来在写入器上写入指定的字节值。这个字节值是用作为整数值传递的字节值的ASCII值来指定的。这个整数值被当作一个参数。
语法。
public void write(int ascii)
参数。这个方法接受一个强制性的参数ascii,它是要写在写入器上的字节值的ASCII值。
返回值。这个方法不返回任何值。
下面的方法说明了write(int)方法的工作。
程序 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);
}
}
}
输出:
0
程序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);
}
}
}
输出:
A