public class day5 {public static void main(String[] args) throws IOException {// 1.定义源文件和目标文件的File对象File f1 = new File("D:/a.jpg");File newFile = new File("D:/aa/newFile.jpg");// 2.定义输入输出流关联文件InputStream in = new FileInputStream(f1);OutputStream out = new FileOutputStream(newFile);// 3.使用输入流读取内容,然后把读取的内容写入目标文件// // 3.(方法1)逐个进行读写操作
// int n;
// while ( (n = in.read() ) !=-1 ){
// out.write(n);
// }
//
// // 3.(方法2)使用缓冲区读写
// byte[] buffer = new byte[10];
// while ( (n = in.read(buffer)) !=-1 ){
// out.write(buffer,0,n);
// }// 3.(方法3)long start = System.currentTimeMillis();// 推荐写法byte[] buffer = new byte[1024];int n ;while ( (n = in.read(buffer)) !=-1 ){out.write(buffer,0,n);}long stop = System.currentTimeMillis();System.out.println("耗时:"+(stop-start));}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!