【发布时间】:2013-05-24 19:07:09
【问题描述】:
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 文件和读取图像文件。我知道读取字节明智和其他字符明智。但我没有得到这个输出。
【问题讨论】:
-
PNG 文件可能包含一个文件结束字符(Windows 中的 ctrl-Z,Linux/Unix 中的 ctrl-D),它会导致为文本设计的 FileReader 结束输入完成了。
-
如果你想读取图像文件你应该使用
Image image = ImageIO.read("File instance OR URL"); -
不,我的目的不是读取图像文件,而只是想清除上面的输出
标签: java filereader fileinputstream