模块 java.base
 java.lang

接口 Appendable

所有已知的实现类:
BufferedWriter , CharArrayWriter , CharBuffer , FileWriter , FilterWriter , LogStream , OutputStreamWriter , PipedWriter , PrintStream , PrintWriter , StringBuffer , StringBuilder , StringWriter , Writer

public interface Appendable
可以附加 char 序列和值的对象。 Appendable 接口必须由其实例旨在从 Formatter 接收格式化输出的任何类实现。

要附加的字符应该是有效的 Unicode 字符,如 Unicode 字符表示 中所述。请注意,增补字符可能由多个 16 位 char 值组成。

Appendables 对于多线程访问来说不一定是安全的。线程安全是扩展和实现此接口的类的责任。

由于此接口可能由具有不同错误处理风格的现有类实现,因此无法保证错误会传播到调用程序。

自从:
1.5
  • 方法总结

    修饰符和类型
    方法
    描述
    append(char c)
    将指定字符附加到此 Appendable
    将指定的字符序列附加到此 Appendable
    append(CharSequence csq, int start, int end)
    将指定字符序列的子序列附加到此 Appendable
  • 方法详情

    • append

      Appendable  append(CharSequence  csq) throws IOException
      将指定的字符序列附加到此 Appendable

      根据实现字符序列 csq 的类,可能不会附加整个序列。例如,如果 csq 是一个 CharBuffer ,那么要附加的子序列由缓冲区的位置和限制定义。

      参数:
      csq - 要追加的字符序列。如果 csqnull ,那么四个字符 "null" 被附加到这个 Appendable 中。
      返回:
      对此 Appendable 的引用
      抛出:
      IOException - 如果发生 I/O 错误
    • append

      Appendable  append(CharSequence  csq, int start, int end) throws IOException
      将指定字符序列的子序列附加到此 Appendable

      csq 不是 null 时调用 out.append(csq, start, end) 形式的方法,其行为与调用完全相同

         out.append(csq.subSequence(start, end)) 
      参数:
      csq - 将追加子序列的字符序列。如果 csqnull ,那么字符将被追加,就好像 csq 包含四个字符 "null" 一样。
      start - 子序列中第一个字符的索引
      end - 子序列中最后一个字符之后的字符的索引
      返回:
      对此 Appendable 的引用
      抛出:
      IndexOutOfBoundsException - 如果 startend 为负,则 start 大于 end,或者 end 大于 csq.length()
      IOException - 如果发生 I/O 错误
    • append

      Appendable  append(char c) throws IOException
      将指定字符附加到此 Appendable
      参数:
      c - 要追加的字符
      返回:
      对此 Appendable 的引用
      抛出:
      IOException - 如果发生 I/O 错误