第一种
public class FileReaderDemo { public static void main(String[] args) throws IOException { FileReader fr = new FileReader("test.txt"); int ch = 0; while((ch=fr.read())!=-1){ System.out.println((char)ch); } fr.close(); } }
第二种
public class FileReaderDemo2 { public static void main(String[] args) throws IOException { FileReader fr = new FileReader("test.txt"); char[] buf = new char[1024]; int len = 0; while((len=fr.read(buf))!=-1){ System.out.println(new String(buf,0,len)); } /*int num = fr.read(buf); System.out.println(num+":"+new String(buf)); */ fr.close(); } }