Java.io.PrintWriter.write() 方法
描述
java.io.PrintWriter.write() 方法写入字符串的一部分。
声明
以下是 java.io.PrintWriter.write() 方法的声明。
public void write(String s,int off,int len)
参数
s − 要写入的字符串。
off − 开始写入字符的偏移量。
len − 要写入的字符数。
返回值
此方法不返回值。
异常
NA
示例
下面的例子展示了 java.io.PrintWriter.write() 方法的使用。
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);
// write substrings
pw.write(s, 0, 5);
pw.write(s, 6, 5);
// flush the writer
pw.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
HelloWorld

