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

