Reset Java BufferedReader after parsing -


i know done mark() , reset(). i'm new reading in files , code doesn't work , know mistake pretty obvious , stupid can't figure out. i've tried moving things around hasn't worked out. goal of code pop joption pane first time null line found(which haven't gotten yet), , return top of file. dumb question if can me out i'd appreciate it. way issue getting ioexception thrown after last line read( executes method each time jbutton clicked ).

public static void filereader( string inputfile , jtextfield array[] ) {     /** local constants **/      final string not_readable = "file not readable!!";     final string io_error     = "input/output error!!";      /** local variables **/      string line;      if ( instream == null )     {         fileopen( inputfile );     }      if ( isreadablefile( inputfile ) )     {        try        {            line = instream.readline();          instream.mark( 64 );           if ( line != null )          {             int j = 0;              ( int = 0; < line.length(); i++ )             {                 if ( character.isdigit( line.charat( ) ) )                 {                     if ( j < array.length )                        array[ j ].settext( line.charat( ) +                                            magicsquaregui.blank );                      j++;                 }             }          }           else          {             instream.close();             instream.reset();          }      }       catch ( ioexception e )      {         system.out.println( io_error );      }       catch ( exception e )      {         system.out.println( error );      }   }    else      system.out.println( not_readable );  } 

you getting error ioexception after try resetting stream.

possibilities:

1) reset calling on type of stream class may not supported. reset not supported types of streams.

2) have read bytes. in case, reset fail. reset supported if bytes not read more mark limit. check line variable , length if reading bytes.

answer updated:

1) need mark before start reading. should this:

     instream.mark( 64 );      line = instream.readline(); 

2) don't close stream unless finished it. closing stream , use reset wrong.

this line instream.close() needs removed current else , put in end of function, after last else.

3) 1 more thing want point out you reading 1st line in text file. stream reader not in loop.

i tested function mentioned changes.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -