2016-01-07 39 views
-1

我解析一个CSV文件,该文件会有点像这个如何忽略特定条件后解析csv文件的其余部分?

07-Jan-2016 
It is better to lead from behind and to put others in front, especially when you celebrate victory when nice things occur. You take the front line when there is danger. Then people will appreciate your leadership. 

The main thing that you have to remember on this journey is, just be nice to everyone and always smile. 

Some Other third Quote 

and some all content here goes on 
--------- 
---------- 
----------- 

我的问题是我怎么能忽略这个特殊的行“Some Other third Quote

我读的CSV解析后的文件文件如下图所示

String csvFile = "ip/ASRER070116.csv"; 
    BufferedReader br = null; 
    String line = ""; 
    try { 
    br = new BufferedReader(new FileReader(csvFile)); 
    while ((line = br.readLine()) != null) { 
    System.out.println(line); 
    } 
    } 

请问如何解决这个问题?

+2

这些问题可以帮助你:我如何在Java中比较字符串(HTTP:/ /stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) - [如何在java中退出while循环?](http://stackoverflow.com/questions/7951690/how -do -i-exit -a-while-loop-in-java) – BackSlash

+3

你总是可以用break来停止while循环 – mimimito

回答

1

您可以检查每行一个字符串,打破了循环当特定条件满足

//inside the loop  
if (line.contains("some_string")) 
    break;