- package cn.IOtest_4method;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class FourMethodAvi {
- public static void main(String[] args) throws IOException {
- //method1("20.14_IO.avi", "Copy1.avi");
- //method2("20.14_IO.avi", "Copy3.avi");
- //method3("20.14_IO.avi", "Copy3.avi");
- method4("20.14_IO.avi", "Copy4.avi");
- }
-
-
- private static void method4(String src, String dest) throws IOException {
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
- byte[] bys = new byte[1024];
- int len = -1;
- while((len = bis.read(bys)) != -1){
- bos.write(bys, 0, len);
- }
- bos.close();
- bis.close();
- }
- private static void method3(String src, String dest) throws IOException {
- FileInputStream bis = new FileInputStream(src);
- FileOutputStream bos = new FileOutputStream(dest);
- byte[] bys = new byte[1024];
- int len = -1;
- while((len = bis.read(bys)) != -1){
- bos.write(bys, 0, len);
- }
- bis.close();
- bos.close();
- }
- private static void method2(String src, String dest) throws IOException {
- BufferedInputStream bis = new BufferedInputStream(new FileInputStream(src));
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
- int ch = -1;
- while((ch = bis.read()) != -1){
- bos.write(ch);
- }
- bis.close();
- bos.close();
- }
- public static void method1(String src , String dest) throws IOException{
- FileInputStream fis = new FileInputStream(src);
- FileOutputStream fos = new FileOutputStream(dest);
- int ch = -1;
- while((ch = fis.read()) != -1){
- fos.write(ch);
- }
- fos.close();
- fis.close();
- }
- }
复制代码 |