Java.io.PrintWriter.print() 方法
描述
java.io.PrintWriter.print() 方法打印一个布尔值。 String.valueOf(boolean) 生成的字符串按照平台默认的字符编码转换成字节,这些字节完全按照write(int)方法的方式写入。
声明
以下是 java.io.PrintWriter.print() 方法的声明。
public void print(boolean b)
参数
b − 要打印的布尔值。
返回值
此方法不返回值。
异常
NA
示例
下面的例子展示了 java.io.PrintWriter.print() 方法的使用。
package com.tutorialspoint;
import java.io.*;
public class PrintWriterDemo {
public static void main(String[] args) {
boolean bool = false;
try {
// create a new writer
PrintWriter pw = new PrintWriter(System.out);
// print a boolean
pw.print(true);
// change the line
pw.println();
// print another boolean
pw.print(bool);
// flush the writer
pw.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
true false

