From ce94c2636e2c01cfc3c04dc6130e2b96ad3c5218 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Wed, 25 Mar 2026 14:49:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E9=98=B6day10-=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=B5=81=E7=9A=84=E5=9F=BA=E6=9C=AC=E4=BD=BF=E7=94=A8(PrintStr?= =?UTF-8?q?eam)(=E4=BA=86=E8=A7=A3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/inmind/printstream_04/Demo14.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 javaSE-day10/src/com/inmind/printstream_04/Demo14.java diff --git a/javaSE-day10/src/com/inmind/printstream_04/Demo14.java b/javaSE-day10/src/com/inmind/printstream_04/Demo14.java new file mode 100644 index 0000000..c9f4eb6 --- /dev/null +++ b/javaSE-day10/src/com/inmind/printstream_04/Demo14.java @@ -0,0 +1,32 @@ +package com.inmind.printstream_04; + +import java.io.FileNotFoundException; +import java.io.PrintStream; + +/* +打印流的基本使用(PrintStream)(了解) +构造方法 +PrintStream(String fileName) 使用指定的文件名创建新的打印流,无需自动换行 + +常用方法: +print():直接输出内容,但不换行 +println():直接输出内容,但换行 + */ +public class Demo14 { + //修改掉sout的打印位置 + public static void main(String[] args) throws FileNotFoundException { + PrintStream ps = new PrintStream("dest.txt"); + System.setOut(ps);//修改了系统级别的打印位置 + System.out.println("这是修改了系统级别的打印位置后的sout"); + } + + //打印流的基本使用 + public static void method(String[] args) throws FileNotFoundException { + //往相对路径dest.txt中打印字符串 + PrintStream ps = new PrintStream("dest.txt"); + ps.println("你好java"); + ps.print("helloworld"); + System.out.println("你好java"); + ps.close(); + } +}