2016-01-07 43 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;