最近在学习java的输入流,用FileInputStream读取文件不能读取全部内容,都去的文件如下图:
注意:文件只有3行!!!!
在myeclipse中的输入如下图:
注意:输出只有2行!!!!
实在找不出哪里错了,还请不吝赐教,非常感谢!
代码如下:
package firPrj;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class FileReaderClass {
public static void main(String []args){
FileReaderClass fileReader = new FileReaderClass();
System.out.println("readByByte:");
fileReader.readByByte("c:\\file.txt");
}
private void readByByte(String fileName){
InputStream in = null;
try{
in = new FileInputStream(fileName);
int tem = -1;
while((tem = in.read()) != -1){
System.out.write(tem);
}
} catch(IOException e){
e.printStackTrace();
} finally{
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}