日期:2014-05-20  浏览次数:20662 次

我要把D盘的文件“aa.txt”复制到E盘上,求代码
代码会使用到输入流和输出流
最好在这2个地方注释下,这个我还不太明白,谢谢了!
java OutputStream

------解决方案--------------------
class Test {
public static void main(String args[]) {
FileInputStream fis = null;
FileOutputStream fos = null;
byte[] buffer = new byte[100];
int temp = 0;
try {
fis = new FileInputStream("D:\\aa.txt");
fos = new FileOutputStream("E:\\aa.txt");
while (true) {
temp = fis.read(buffer, 0, buffer.length);
if (temp == -1) {
break;
}
fos.write(buffer, 0, temp);
}
} catch (Exception e) {
System.out.println(e);
} finally {
try {
fis.close();
fos.close();
} catch (Exception e2) {
System.out.println(e2);
}
}

}
}

------解决方案--------------------
引用:
temp = fis.read(buffer, 0, buffer.length);这句我不理解,求解释 
从源文件中将最多  buffer.length个字节的数据读入一个 byte 数组中,并用一个int型的变量保存下来,以便用于在目标文件中写入这么多数据。
fos.write(buffer, 0, temp);



这句话的意思是,读buffer这个缓冲区,从哪开始读啊?从0开始读,把所以的都读出来