FileReader fr=new FileReader("D:\\workspace\\MyLearn\\count.txt"); //可以换成工程目录下的其他文本文件 BufferedReader br=new BufferedReader(fr); while(br.readLine()!=null){ String s=br.readLine(); System.out.println(s); }用readLine后
s最后会变空
public static void main(String[] args) throws Exception { File file = new File("d:\\a.txt"); FileReader reader = new FileReader(file); int fileLen = (int)file.length(); char[] chars = new char[fileLen]; reader.read(chars); String txt = String.valueOf(chars); System.out.println(txt); }
txt不会