Java基礎之字節複製

public class Copy1 {

    public static void main(String[] args) {

        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            FileInputStream fis = new FileInputStream("e:/io/1.txt");
            FileOutputStream fos = new FileOutputStream("d:/io/1.txt");

            bis = new BufferedInputStream(fis);
            bos = new BufferedOutputStream(fos);

            byte[] b = new byte[1024];
            int len = 0;

            while((len = bis.read(b)) != -1){

                bos.write(b,0,len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                if(bos != null){
                    bos.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if(bis != null){
                    bis.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章