Search code examples
javagwtcsvstreambufferedreader

How do i temporarily close a buffered reader in java gwt server side?


i was reading a csv file on my application using java with GWT framework. is there a way for me to temporarily close the buffered reader?

i mean is there a way for me to stop reading the csv file when i find the specific line that I'm looking for?

bufferedReader.close() causes an error. it says error on server because stream is closed. bufferedReader.reset() doesnt work either it says it's not supported.

please help. thanks in advance.

edit.

while ((line = br.readLine()) != accountColumn ) {
if (line.equals(accountColumn)) {

    System.out.println(line);
    checker = true;
    String[] columns = line.split(cvsSplitBy);
    int totalColumns = columns.length;
    int col = 0;
    while (col < totalColumns) {
        log.append(columns[col] + "\n");
        col++;
    }
    JOptionPane.showMessageDialog(frame,"SAME COLUMNS DETECTED, READY FOR UPLOAD");

output.

LEDGER,EXTRACT_NAME,COUNTRY,ENTITY,TAX_CATEGORY,TAX_SUB_CATEGORY,TAX_ACCOUNT_TYPE,TAX_ACCOUNT,ACCUNT_TYPE,TAX_DRIVER,USE_FLAG,INPUT_ID,INPUT_NAME,DEL_FLAG
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564
1,456,465,46,5456,456,4,45,5656456,56,564,6546,654,6564

it finds the specific line that im looking for but continues to read the rest


Solution

  • You cannot temporarily close the buffer reader. You probably get an exception when you close it because you are still in the while loop and the condition line = br.readLine() will execute again and throw an exception.

    You should exit the while loop using break and close the buffer afterwards.