FileInputStream与FileReader [英] FileInputStream vs FileReader

查看:206
本文介绍了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();

当我使用 FileReader FileWriter 要读取和写入mp4文件, output.mp4 文件无法很好地呈现。但是,当我使用 FileInputStream FileOutputStream 时,它运作良好。

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.

那么我可以得出结论 FileReader FileWriter 仅用于读写文本吗?

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

推荐答案

是的,您的结论是 Reader Writer <的正确子类/ code>用于读/写文本内容。 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天全站免登陆