Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Restart at beginning of file once the end is reached

807605Aug 15 2007 — edited Aug 16 2007
Without closing and re-opening the file stream, is it possible to just start back over at the beginning of the BufferReader? The problem with my code is it isn't pulling all of the results because when it goes through one pass, it's reading the entire file, and when I increment i, it doesn't do anything because the BufferReader is at the end already. At least that's what I am thinking.

        try
        {
            File temp = new File ("./" + filename + ".lst");
            File txtFile = new File (libraryList);
            FileInputStream fstream = new FileInputStream (txtFile);
            DataInputStream in = new DataInputStream (fstream);
            BufferedReader br = new BufferedReader (new InputStreamReader (in));
            
            ArrayList al = new ArrayList ();
            String[] line;
            if (!temp.exists ())
            {
                try
                {
                    FileWriter fileOut = new FileWriter (temp, false);
                    BufferedWriter out = new BufferedWriter (fileOut);
                    
                    for (int i = 0; i < currentPlaylistItems.size (); i++)
                    {
                        String[] song = currentPlaylistItems.get (i).toString ().replaceAll (" \\(.*$", "").split (" - ");
                        while(br.readLine () != null)
                        {
                            line = br.readLine ().split ("\t");
                            if (song[0].equals (line[1]) && song[1].equals (line[2]))
                            {
                                System.out.println ("The path to " + line[1] + " - " + line[2] + " is " + line[3]);
                            }
                        // need something right here to reset the reader to the very beginning
                        }
                    }
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
        catch (Exception e)
        {
            System.out.println (e);
        }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 13 2007
Added on Aug 15 2007
9 comments
1,196 views