File file = new File("E:\\hello.txt");
FileInputStream fos = new FileInputStream(file);
try {
while (fos.read()!=-1) {
System.out.print((char)fos.read()+"");
}
为什么读东西的时候第一个不读读第二个,比如文件是123456789
读出的是2468?。
因为你的fos.read()这个读取方法在while里面执行了一次之后,在循环体里面又执行了一次啊。你要一个一个读就应该这样写:
int n = -1;