gpt4 book ai didi

java - FileReader 和 FileInputStream 的不同输出

转载 作者:行者123 更新时间:2023-11-30 04:22:22 25 4
gpt4 key购买 nike

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);
}
}

输出:

reading a file : fileReader:104 fileInputStream:104
resding PNG : fileReader:8240 fileInputStream:137

我正在使用 FileReader 和 FileInputStream 来读取 txt 文件和读取图像文件。我知道按字节读取和按其他字符读取。但我没有得到这个输出。

最佳答案

文件阅读器:

Convenience class for reading character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are appropriate.

文件输入流:

FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.

关于java - FileReader 和 FileInputStream 的不同输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16742017/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com