比如 FileWrite 有一个write方法,write(int c),这里的int 型参数c是什么意思,是每次写c个字符吗?
我的java估计和楼上不是一个版本
/**
* Writes a single character.
*
* @exception IOException If an I/O error occurs
*/
public void write(int c) throws IOException {
se.write(c);
}
好奇顺便点进去看看。由于这部分不开源,是反编译器看到的代码。
public void write(int var1) throws IOException {
char[] var2 = new char[]{(char)var1};
this.write((char[])var2, 0, 1);
}
public void write(char[] var1, int var2, int var3) throws IOException {
synchronized(this.lock) {
this.ensureOpen();
if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
if (var3 != 0) {
this.implWrite(var1, var2, var3);
}
} else {
throw new IndexOutOfBoundsException();
}
}
}
就是一个int的值,强转char类型(相当于byte但是不带符号,基本等同),最终产生一个char数组,从0开始,长度1,写入缓存。
比如这个int值是48,就存了个0x30或者可称为'0'到文件里。
文档里面写:
void write(int b)
Writes the specified byte (the low eight bits of the argument b) to the underlying output stream.
也就是把int b这个整数的最低8位构成的那个字节,写入输出流。