Files
javaSE-0113/javaSE-day09/src/com/inmind/writer04/Demo13.java

27 lines
912 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.writer04;
import java.io.FileWriter;
import java.io.IOException;
/*
刷新和关闭方法的区别
当我们想将缓冲区的数据输出到文件中但是该字符输出流还想继续使用时那就要使用flush方法
总结:
1.flush方法的作用将缓冲区的数据刷新到硬盘上但是io流的资源没有释放的
2.close方法释放资源之前会默认调用一次flush但是调用close方法该流就不能再使用否则报异常IOException: Stream closed
*/
public class Demo13 {
public static void main(String[] args) throws IOException {
//创建字符输出流
FileWriter fw = new FileWriter("a.txt");
fw.write("数据在哪里");
//主要刷新到文件中
fw.flush();
fw.write("数据在这");
fw.close();
System.out.println("程序结束");
}
}