美文网首页
字节流 字符流

字节流 字符流

作者: 啷里个啷里个啷个里个啷 | 来源:发表于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 
 


相关文章

  • Java | 两个IO实例demo

    套路:.字节流(如InputStream )转换成字符流(如InputStreamReader),字符流转成缓冲字...

  • IO Stream - 字符流

    字符流 字符流出现的原因1.字符流介绍:由于字节流操作中文不是特别方便,所以Java提供了字符流字符流 = 字节流...

  • java中有几种类型的流?JDK为每种类型的流提供了一些抽象类以

    字节流,字符流。字节流继承于InputStream OutputStream,字符流继承于InputStreamR...

  • NO.31 文件数据IO操作

    字符流: 字符流与字节流的区别在于读写单位为字符,但是字符流底层本质还是读写字节,只是字符与字节的转换工作交给了字...

  • Java中有几种类型的流?

    字节流和字符流。字节流继承于InputStream、OutputStream,字符流继承于Reader、Write...

  • HttpServletResponse

    字节流可以写任何数据,字符流只能写字符数据 getOutputStream字节流,getWriter字符流 1、r...

  • IO

    字节流 字符流 节点流 转换 流...

  • IO流 2018-05-07

    字节流和字符流: 1字节流(均为抽象类):在字节流中定义了方法read(),用于从字节流中读取对象: public...

  • I/O流之文件流

    文件流可以分为字节流和字符流字节流字节流可以对任何文件进行操作 ,但效率不如字符流高字节流分为字节输入流和字节输...

  • Java IO 流学习总结

    Java流操作有关的类或接口 Java流类图结构: 字符流和字节流 字符流的由来: 因为数据编码的不同,而有了对字...

网友评论

      本文标题:字节流 字符流

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