1 package com.ht.util; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileNotFoundException; 6 import java.io.IOException; 7 import java.io.InputStreamReader; 8 import java.io.Reader; 9 10 public class IoReader { 11 public static void main(String[] args) { 12 File fileName = new File("D:/test.txt"); 13 Reader reader = null; 14 char[] tem = new char[1000]; 15 int chared = 0; 16 try { 17 //注意编码 18 reader = new InputStreamReader(new FileInputStream(fileName),"gb2312"); 19 while((chared = reader.read(tem)) != -1){ 20 // '\r' 判断一行是否结束 21 if((chared == tem.length)&&(tem[tem.length-1] != '\r')){ 22 System.out.println(tem); 23 }else{ 24 for(int i = 0 ; i < chared;i++){ 25 if(tem[i] == '\r'){ 26 continue; 27 }else{ 28 System.out.print(tem[i]); 29 } 30 } 31 } 32 } 33 reader.close(); 34 } catch (FileNotFoundException e) { 35 e.printStackTrace(); 36 } catch (IOException e) { 37 e.printStackTrace(); 38 } 39 } 40 }
浙公网安备 33010602011771号