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

版权声明:本文为博主原创文章,分享是一种美德,转载请注明出处 https://blog.csdn.net/qq_35794278/article/details/86503881
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;
    }

猜你喜欢

转载自blog.csdn.net/qq_35794278/article/details/86503881