本帖最后由 pk49800 于 2014-6-7 15:21 编辑
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class TestRead {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- File f = new File("d:\\da.txt");
- FileInputStream fis = new FileInputStream(f);
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- //int ch = br.read();
- while(true){
- int ch = br.read();
- if(ch != -1)
- System.out.println((char)ch);
- else
- break;
- }
- /*while(true){
- int ch = br.read();
- if(ch != -1)
- System.out.println((char)ch);
- else
- break;
- }
- */
- br.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
复制代码 改成这样就不会出现了,因为你的输出把文件结尾的标识“-1”都打印出来,但是这个字符在ASII码表里面是没有对应的,所以不能识别
|