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);
}
在此代码中,if语句从不工作,但在tester.txt
中有2个句子写在新行上。 这是为什么呢?为什么片段无法检测到行尾
这就是我使用'System.getProperty(“line.separator”)''的原因! –
@Suhail,但是当你阅读和比较单个字符时,你永远不会检测到多字符EOL。 –
@马特球是的,我现在意识到。 –