-
打印流借助文件将数据存储在硬盘中,实现数据的持久化保存
-
打印流是最为方便的流,可以打印任何形式的数据.如: 小数,整数和字符串等
-
打印流分为字节打印流和字符打印流:
-
字符打印流 PrintWriter: print方法可以打印各种类型数据
-
字节打印流 PrintStream: println方法可以打印各种类型的数据
-
-
PrintWriter和PrintStream不会抛出异常,用户通过检测错误状态获取错误信息
-
PrintWriter,PrintStream有自动刷新flush的能力
-
代码示例:
-
import java.io.FileNotFoundException; import java.io.PrintWriter; public class PrintWriterTest { public static void main(String[] args) throws FileNotFoundException { PrintWriter p = new PrintWriter("E:/deom.html"); p.println("<a href = ">百度<"/a>"); p.close(); } }
Java IO流之打印流PrintWriter,PrintStream
最新推荐文章于 2022-09-29 23:44:41 发布