FileInputStream 与 FileReader [英] FileInputStream vs 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
的子类用于读取/写入文本内容.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屋!