进阶day10-打印流的基本使用(PrintStream)(了解)
This commit is contained in:
32
javaSE-day10/src/com/inmind/printstream_04/Demo14.java
Normal file
32
javaSE-day10/src/com/inmind/printstream_04/Demo14.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user