文件的复制通过字节流和缓冲流(Buffered)
public class CopyBufferedFileByStream {
public static void main(String[] args) {
try {
FileInputStream fileInputStream = new FileInputStream("learn.txt");
FileOutputStream fileOutputStream = new FileOutputStream("learn222.txt");
byte b [] = new byte[1024];
BufferedInputStream bis =
new BufferedInputStream(fileInputStream);
BufferedOutputStream bos =
new BufferedOutputStream(fileOutputStream);
int count = 0;
long before = System.currentTimeMillis();
while (bis.read(b) != -1) {
bos.write(b);
count++;
}
System.out.println(count);
System.out.println(System.currentTimeMillis()-before);
// byte b [] = new byte[1024];
// while(fileInputStream.read(b)!= -1){
// fileOutputStream.write(b);
// }
bos.close();
bis.close();
fileInputStream.close();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
本文标题:文件的复制通过字节流和缓冲流(Buffered)
本文链接:https://www.haomeiwen.com/subject/qaldjftx.html
网友评论