Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 5th, 2006, 1:02 AM   #1
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
BufferedReader

I'm not to sure how to move the pointer on the file your working with. For example in the following code: the 2 print statements (in blue) read lines 1 - 3. but the writting in orange continues reading the file. How do i move the pointer up to line 1 again to that the writting in orange does not continue from where the writting in blue left off ?

  BufferedReader input2 = new BufferedReader (new FileReader ("C:\\output.txt"));

                //int intNumberofLines = 0; // default 0 because there is always 1 line to read

                // first we get all the data so that it isn't written over
                
                intNumberofLines = Integer.valueOf (input2.readLine ()).intValue (); 
                c.print(input2.readLine()); 
                c.print(input2.readLine());  
                //c.print ("2nd line is: " + Integer.valueOf (input2.readLine ()).intValue ()); 
                //c.print ("3rd line is: " + Integer.valueOf (input2.readLine ()).intValue ()); 
                //c.print ("number of lines is" + intNumberofLines);

               // String inputString [] = new String [intNumberofLines]; // array large enough to hold all text data
                for (int y = 0 ; y < (intNumberofLines - 1) ; y++) // +1 because we've already read the int for line 1.
                {
                    inputString [y] = input2.readLine (); // because array starts at 0 not 1.
                    c.print ("String is: " + inputString [y]);
                }

                inputStringFinal = new String [intNumberofLines + 1];  // +1 because the tempLicense is added to the array.
                blnStringDeclared = true; // so it can be used when (inputAns = 1)
                
                    // cloning array and adding the final License
                    for (int i = 0 ; i < intNumberofLines ; i++) // cloning the array
                {
                    inputStringFinal [i] = tempLicense;
                }

                inputStringFinal [intNumberofLines] =  tempLicense; // the last boundary is used for the license just created
                
                c.print ("first line 1: " + input2.readLine());
                c.print ("second line 2: " + input2.readLine());
                c.print ("third line 3: " + input2.readLine());
                
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC