美文网首页
字节流 字符流

字节流 字符流

作者: 啷里个啷里个啷个里个啷 | 来源:发表于2021-07-30 10:34 被阅读0次
    
    FileInputStream
    FileOutputStream
    
    public void copyWithSteam(String srcPath,String destPath){
        System.out.println("Steam");
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            File srcFile = new File(srcPath);
            File destFile = new File(destPath);
    
            fis = new FileInputStream(srcFile);
            fos = new FileOutputStream(destFile);
    
            byte[] buffer = new byte[8192];
            int len;
            while((len = fis.read(buffer)) != -1){
    
                fos.write(buffer,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
    
            if (fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    上述为字节流,字符流和字节流写法一致。
    字符流使用
    FileReader
    FileWriter 
     
    
    
    

    相关文章

      网友评论

          本文标题:字节流 字符流

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