2 Replies Latest reply: May 29, 2012 11:07 AM by gimbal2 RSS

    problem with mark file

      Hi everyone!! I am reading characters from a file, and need to mark (with mark) a specific word in the file, read more characters, and the come back to the mark (with reset).

      This is a snapshot of the code (without try catch):
                     FileInputStream fstream = new FileInputStream(url_dic);
                     DataInputStream in = new DataInputStream(fstream);
                     BufferedReader br = new BufferedReader(new InputStreamReader(in));
                     int number_words=0;
                     String strLine;
                     }while(strLine.length()== this.long_word);
                     System.out.println("last word="+strLine);
      But when the file has too many characters, I get this exception: “Mark invalid”

      Why?? can someone please explain how mark works??

      Thank you very very much
        • 1. Re: problem with mark file
          You are calling mark(1), which sets a read-ahead limit of 1, then calling readLine(), which is almost certainly going to need to read more than one character.

          I suggest another look at the Javadoc. There's not much point in writing arbitrary code and wondering why it doesn't work.
          • 2. Re: problem with mark file
            In stead of running to this forum right away, why don't you take a look at the javadoc for the mark() method of BufferedReader?


            Especially the part about that integer parameter for which you are now passing 1.