s-day10-打印流的基本使用(PrintStream)(了解)

This commit is contained in:
2026-08-12 14:13:54 +08:00
parent d2fc438a3b
commit 3ee8ad4d0c
@@ -0,0 +1,28 @@
package com.inmind.print_stream04;
import java.io.PrintStream;
/*
打印流的基本使用(PrintStream)(了解)
构造方法
PrintStream(String fileName) 使用指定的文件名创建新的打印流,无需自动换行
常用方法:
print():直接输出内容,但不换行
println():直接输出内容,但换行
*/
public class Demo12 {
public static void main(String[] args) throws Exception {
//往相对路径dest.txt中打印字符串
PrintStream ps = new PrintStream("dest.txt");
//调用打印输出功能
ps.println("我是谁");
ps.println("我在哪");
ps.print("我在干嘛");
ps.close();
// System.setOut(ps); 不要这么做
System.out.println("我是System打印的");
}
}