java printwrite_Java PrintWriter write(int)用法及代码示例
Java中的PrintWriter類的write(int)方法用于在流上寫入指定的字符。使用以整數值傳遞的字符的ASCII值指定此字符。該整數值用作參數。
用法:
public void write(int ascii)
參數:此方法接受強制性參數ascii,該參數是要寫入流中的字符的ASCII值。
返回值:此方法不返回任何值。
以下方法說明了write(int)方法的用法:
示例1:
// Java program to demonstrate
// PrintWriter write(int) method
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
// Create a PrintWriter instance
PrintWriter writer
= new PrintWriter(System.out);
// Write the character '0' to this writer
// using write() method
// This will put the string in the stream
// 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
// PrintWriter write(int) method
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
// Create a PrintWriter instance
PrintWriter writer
= new PrintWriter(System.out);
// Write the character 'A' to this writer
// using write() method
// This will put the string in the stream
// till it is printed on the console
writer.write(65);
writer.flush();
}
catch (Exception e) {
System.out.println(e);
}
}
}
輸出:
A
總結
以上是生活随笔為你收集整理的java printwrite_Java PrintWriter write(int)用法及代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux(Unix)时钟同步ntpd服
- 下一篇: java线程池应用的好处_java高级应