基本代码:
FileInputStream fis = new FileInputStream("E:\\Java基础资料\\a.txt");
FileOutputStream fos = new FileOutputStream("E:\\Java基础资料\\b.txt" );
while (true) {
int b = fis.read();
if (b == -1)
break;
fos.write(b);
}
fos.close();
fis.close();
----------------------------------------------------------------
改进:
FileInputStream fis = new FileInputStream("E:\\Java基础资料\\a.txt");
FileOutputStream fos = new FileOutputStream("E:\\Java基础资料\\b.txt" );
byte[] bytes = new byte[5];
while (true) {
int len = fis.read(bytes);
if (len == -1)
break;
fos.write(bytes, 0, len);
}
fos.close();
fis.close();