错误记录

(1)

再练习IO时遇到的一个小错误,注意即可避免:

		File readFile = new File("E:\\IO\\test.txt");
		File writeFile = new File("E:\\IO\\rr.txt");
		
		try {
			FileReader fr = new FileReader(readFile);
			FileWriter fw = new FileWriter(writeFile);
			BufferedReader br = new BufferedReader(fr);
			BufferedWriter bw = new BufferedWriter(fw);
			while(br.readLine()!=null){
				bw.write(br.readLine());
			}
			br.close();
			bw.flush();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 readLine()方法与Iterator的next()方法有些相似,在上面代码中,读到最后一行时,while中的判断条件不为空,但其下读入时已成空值,抛出空指针错误。

你可能感兴趣的:(错误)