import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyBytes {
public static void main(String[] args) throws IOException {
FileInputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream("C:\\int.txt");
out = new FileOutputStream("C:\\out.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
}
}
这段代码中的数字 (-1) 来自哪里?
while ((c = in.read()) != -1) {
out.write(c);.
我尝试查看 java 教程,但它只给了我一个令人困惑的图表。
编辑:我将 -1 的值更改为 -4,这导致最后一个字符被多次写入。这是为什么?