目录

void print(boolean b)

描述 (Description)

java.io.PrintWriter.print()方法输出一个布尔值。 String.valueOf(boolean)生成的字符串根据平台的默认字符编码转换为字节,这些字节的写入方式与write(int)方法完全相同。

声明 (Declaration)

以下是java.io.PrintWriter.print()方法的声明。

public void print(boolean b)

参数 (Parameters)

b - 要打印的布尔值。

返回值 (Return Value)

此方法不返回值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.io.PrintWriter.print()方法的用法。

package com.iowiki;
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
↑回到顶部↑
WIKI教程 @2018