我听说:FileReader是高级流,BufferedReader是低级流,并且关注此网站:http://way2java.com/io/chaining-of-streams/
“链接规则”
如果流被链接就像那样,你将陷入编译错误。遵循以下规则。
但是:
`
public class CopyLines {
public static void main(String[] args) throws IOException {
BufferedReader inputStream = null;
PrintWriter outputStream = null;
try {
inputStream = new BufferedReader(new FileReader("xanadu.txt"));// not like above website say
outputStream = new PrintWriter(new FileWriter("characteroutput.txt"));
String l;
while ((l = inputStream.readLine()) != null) {
outputStream.println(l);
}
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
}`
有人告诉我,为什么上面的代码也正确