功能:将内容写入文本
package com.cool.io.out;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
public class PrintStreamTest {
public static void main(String[] args) {
PrintStream pout = null;
try {
File file = new File("d:" + File.separator + "123.txt");
pout = new PrintStream(file);
pout.println("床前明月光,");
pout.println("疑是地上霜。");
} catch (FileNotFoundException e) {
} finally {
if (pout != null) {
pout.flush();
pout.close();
}
}
}
}
本文提供了一个使用Java中的PrintStream类将字符串写入到指定文件的示例代码。通过创建PrintStream实例并指向目标文件,可以轻松地将文本内容写入到文件中。

被折叠的 条评论
为什么被折叠?



