我想讓程序找到「[DesiredText]」並檢查下一行是否爲空,然後如果是我想取空行的位置。我看到一些例子,但我不能正常工作。歡迎所有建議和線索。如何檢查文本文件中的下一行是否爲空?
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
if ((line.contains("[DesiredText]") && br.readLine().isEmpty())) {
RandomAccessFile raf = new RandomAccessFile("D:\\Temp.txt","r");
long position = raf.getFilePointer();
pozycje.add(position);
raf.close();
}
}
_I無法正常工作_怎麼樣? –