zoukankan      html  css  js  c++  java
  • 打印流PrintStream

    打印流PrintStream

    • public class PrintStream
      extends FilterOutputStream
      implements Appendable, Closeable

      A PrintStream为另一个输出流添加了功能,即能够方便地打印各种数据值的表示。还提供了另外两个功能。与其他输出流不同, PrintStream从不抛出IOException ;相反,异常情况只是设置一个可以通过checkError方法测试的内部标志。可以选择一个PrintStream ,以便自动刷新;这意味着flush字节数组写入方法后自动调用,所述一个println方法被调用时,或者一个新行字符或字节( ' ' )被写入。

      由印刷的所有字符PrintStream被转换成使用平台的默认字符编码字节。 在需要编写字符而不是字节的情况下,应使用PrintWriter类。

     

      • Constructor and Description
        PrintStream(File file) 使用指定的文件创建一个新的打印流,而不需要自动换行。
        PrintStream(File file, String csn) 使用指定的文件和字符集创建新的打印流,而不需要自动换行。
        PrintStream(OutputStream out) 创建一个新的打印流。
        PrintStream(OutputStream out, boolean autoFlush) 创建一个新的打印流。
        PrintStream(OutputStream out, boolean autoFlush, String encoding) 创建一个新的打印流。
        PrintStream(String fileName) 使用指定的文件名创建新的打印流,无需自动换行。
        PrintStream(String fileName, String csn) 创建一个新的打印流,不需要自动换行,具有指定的文件名和字符集

    image-20200513125603131image-20200513130402576

    public class Demo07Main {
      public static void main(String[] args) {
          PrintStream printStream = null;
          try {
              printStream = new PrintStream("io\f.txt");
              printStream.println("你好");
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }finally {
              if (printStream != null){
                  printStream.close();
              }
          }

      }
    }

    image-20200513130434778

    try {
      PrintStream printStream = new PrintStream("io\打印输出地址.txt");
      System.setOut(printStream);//把输出语句的目的地改为了打印流的目的地
      System.out.println("hahhhah");
      printStream.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

     

  • 相关阅读:
    使用VS2013自带的PreEmptive Dotfuscator and Analytis来混淆C#代码
    jQuery发布1.9正式版,最后支持IE 6/7/8
    response的contentType的类型值Response.ContentType
    svn 切出指定版本、更改版本名称、删除分支
    js中url解码
    如何判断一个变量是否是utf-8
    mysql explain详解
    PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone
    winScp上传文件时,如何过滤制定文件
    winScp如何通过隧道代理进行远程连接
  • 原文地址:https://www.cnblogs.com/lxy522/p/12881821.html
Copyright © 2011-2022 走看看