java.io.writer的append和write方法有什么区别? [英] What is the difference between append and write methods of java.io.writer?

查看:238
本文介绍了java.io.writer的append和write方法有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.io.Writer 界面有两个方法叫做追加和写。这两者有什么区别?它甚至说

The java.io.Writer interface has two methods called append and write. What are the differences between these two? It even says that


调用此方法的形式 out.append(c)的行为方式与调用完全相同 out.write(c)

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation out.write(c)

那么有两个方法名称变体的原因是什么?

so what is the reason for having two method name variants?

推荐答案

append()和write()之间存在细微差别。所有这些都可以通过阅读Javadocs来解决。暗示。 ;)

There are minor differences between append() and write(). All of which you can work out by reading the Javadocs. Hint. ;)


  • write只接受一个不能为null的字符串并返回 void

  • append将接受任何CharSequence,它可以为null并返回Writer,以便它可以被链接。

write是在CharSequence可用之前创建的旧样式格式。

write is an older style format created before CharSequence was available.

这些方法已超载,因此存在

These methods are overloaded so that there is a


  • write(int)其中 int 被强制转换为char 。 append(char)必须是char类型。

  • write(char [] chars)接受一个char数组,没有等效的append()。

  • write(int) where the int is cast to a char. append(char) must be a char type.
  • write(char[] chars) takes an array of char, there is no equivalent append().

这篇关于java.io.writer的append和write方法有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆