首先,- public class FileWriter extends OutputStreamWriter
复制代码 ,FileWriter 继承自OutputStreamWriter,OutputStreamWriter中write(int)定义为
- public void write(int c) throws IOException {
- se.write(c);
- }
复制代码
而se是StreamEncoder类的对象,而StreamEncoder中write(int)定义为
- public void write(int c) throws IOException {
- char cbuf[] = new char[1];
- cbuf[0] = (char) c;
- write(cbuf, 0, 1);
- }
复制代码
看到了吧,int先转化为了char类型,因此输出为char类型.
遇到不明白的,先看源代码,能解决大部分问题. |