Java FileReader和FileInputStream的不同输出

Java FileReader和FileInputStream的不同输出,java,filereader,fileinputstream,Java,Filereader,Fileinputstream,输出: import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { FileReader fileReader1 = new FileReader("C:\\test\\input.txt");

输出:

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
public class Main {
    public static void main(String[] args) throws IOException {
        FileReader fileReader1 = new FileReader("C:\\test\\input.txt");
        FileInputStream fileInputStream1 = new FileInputStream("C:\\test\\input.txt");
        FileReader fileReader2 = new FileReader("C:\\test\\abc.png");
        FileInputStream fileInputStream2 = new FileInputStream("C:\\test\\abc.png");

        int ab=fileReader1.read(); 
        int bc=fileInputStream1.read();

        int ab1=fileReader2.read();
        int bc1=fileInputStream2.read();

        System.out.println("reading a file : fileReader:"+ab+" fileInputStream:"+bc);
        System.out.println("resding  PNG : fileReader:"+ab1+" fileInputStream:"+bc1);
    }
}
我使用FileReader和FileInputStream来读取txt文件和图像文件。我知道读取字节和其他字符。但是我没有得到这个输出。

文件阅读器:

阅读字符文件的便利类。此类的构造函数假定默认字符编码和默认字节缓冲区大小是合适的

FileInputStream:

FileInputStream用于读取原始字节流,如图像数据。要读取字符流,请考虑使用FieleRADER。


PNG文件中的第一个字节是0x89,或137位小数。FileInputStream按原样报告字节,而FileReader假定它是Windows 1252代码页中的一个字符,并将其转换为相应的UTF-8字符代码0x2030或8240十进制。(假设您在Windows计算机上以默认代码页1252运行代码)。

PNG文件可能包含一个文件结尾字符(Windows中为ctrl-Z,Linux/Unix中为ctrl-D),该字符使专为文本设计的文件读取器断定输入已完成。如果您要读取图像文件,应使用
image image=ImageIO.read(“文件实例或URL”);
不,我的目标不是读取图像文件,只是想清除上面的输出。我的txt输入文件大小为1KB PNG输入文件大小为274KB,这与此完全无关。关键是,你不应该在二进制文件上使用读取器,或者在任何你事先不知道是文本的文件上使用读取器。
reading a file : fileReader:104 fileInputStream:104
resding  PNG : fileReader:8240 fileInputStream:137