缓冲流

作者: 啷里个啷里个啷个里个啷 | 来源:发表于2021-07-29 18:35 被阅读0次
    BufferedInputStream
    BufferedOutputStream
    
    public void copyWithBufferedSteam(String srcPath,String destPath){
            System.out.println("buffered steam");
    
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                File srcFile = new File(srcPath);
                File destFile = new File(destPath);
    
                FileInputStream fis = new FileInputStream(srcFile);
                FileOutputStream fos = new FileOutputStream(destFile);
    
                bis = new BufferedInputStream(fis);
                bos = new BufferedOutputStream(fos);
    
                byte[] buffer = new byte[8192];
                int len;
                while ((len = bis.read(buffer)) != -1){
                    bos.write(buffer,0,len);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (bis != null){
                    try {
                        bis.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (bos != null){
                    try {
                        bos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:缓冲流

          本文链接:https://www.haomeiwen.com/subject/wwassltx.html