天天看点

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

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;
    }