【发布时间】:2011-08-13 05:23:11
【问题描述】:
FileReader reader = new FileReader("d:\\UnderTest\\AVS\\tester.txt");
char ch;
int x;
while( ( x = reader.read() ) != -1 ) {
// I use the following statement to detect EOL
if( Character.toString((char)x) == System.getProperty("line.separator") ) {
System.out.println("new line encountered !");
} System.out.print( (char)x );
}
虽然在tester.txt 中有两个句子写在新行上,但在这段代码中 if 语句永远不会起作用。
为什么呢 ?
【问题讨论】: