FileInputStream 与 FileReader [英] FileInputStream vs FileReader

查看:19
本文介绍了FileInputStream 与 FileReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileReader rd=new FileReader("new.mp4");
FileWriter wr=new FileWriter("output.mp4");
int ch;
while((ch=rd.read())!=-1)
  wr.write(ch);

wr.flush();
wr.close();

当我使用FileReaderFileWriter读写mp4文件时,output.mp4文件不能很好地呈现.但是当我使用 FileInputStreamFileOutputStream 时,它运行良好.

When I use the FileReader and FileWriter to read and write an mp4 file, the output.mp4 file can't be rendered well. But when I use FileInputStream and FileOutputStream instead it worked well.

那么我可以得出结论 FileReaderFileWriter 仅用于读取和写入文本吗?

So can I conclude FileReader and FileWriter are only for reading and writing text?

推荐答案

是的,您的结论是正确的 ReaderWriter 的子类用于读取/写入文本内容.InputStream/OutputStream 用于二进制内容.如果您查看文档:

Yes, your conclusion is correct subclasses of Reader and Writer are for reading/writing text content. InputStream / OutputStream are for binary content. If you take a look at the documentation:

Reader - 读取字符流的抽象类

Reader - Abstract class for reading character streams

InputStream - 抽象类是所有表示字节输入流的类的超类.

InputStream - Abstract class is the superclass of all classes representing an input stream of bytes.

这篇关于FileInputStream 与 FileReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆