File file = new File("1.txt");Reader reader = null;try {reader = new FileReader(file);} catch (FileNotFoundException e) {e.printStackTrace();}
//第一种方法int data = 0;try {while(((data = reader.read()) != -1)){System.out.print((char)data);}reader.close();} catch (IOException e) {e.printStackTrace();}
int data = 0;char[] ch = new char[5];String str=new String();try {while((data = reader.read(ch)) != -1){str += new String(ch,0,data);}} catch (IOException e) {e.printStackTrace();}System.out.println(str);
填充char数组的原理,数组长度为5。
根据如图的顺序传入值,假如传入到3时没值传入后面的数值是上一次传入的值。
