BufferWriter中 writer()与append()的区别

2022-06-29 10:15:31
apend方法中参数可以为null  会以字符串"null"的形式添加到文件中  writer会报空指针异常
append可以这么写 BufferWriter.append("").append("").append("").append("").append("")   
writer只能写一个  也就是说writer的返回值是空  而append的返回值Writer(BufferWriter的超类)

以下是源码

public class BufferedWriter extends Writer   //Writer   是BufferedWriter 的超类

append()的源码  可以看出有判空操作与返回值 调用了write
    public Writer append(CharSequence csq) throws IOException {
	if (csq == null)
	    write("null");
	else
	    write(csq.toString());
    	return this;
    }
  • 作者:你可拉倒吧
  • 原文链接:https://blog.csdn.net/qq_35794278/article/details/86503881
    更新时间:2022-06-29 10:15:31