Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on reseting file position

Status
Not open for further replies.

iSeriesCodePoet

Programmer
Jan 11, 2001
1,373
US
How do I reset the file position to the beginning of the file? Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
What class are you using to read the file? For example, if you were using the
Code:
RandomAccessFile
class to read your file then you could always call the
Code:
seek
method and pass 0 as the offset to place the file-pointer at the beginning of the file.
 
I am using FileReader. Is this what you are looking for. I am quite new to the OO and Java world. Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Have you tried calling the
Code:
reset
method? I can't remember if this is supported in
Code:
InputStreamReader
which is the class that
Code:
FileReader
inherits from. It will throw an
Code:
IOException
if it is not supported, otherwise it should reset the file-pointer to the beginning of the file.

 
I tried that, it crashed on me when I did. I saw that in there and thought it made sense. How do you open a file again after you close it? I thought of trying that. Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Instead of hacking it... switch to using
Code:
RandomAccessFile
to read your files.
Code:
FileReader
is really intended to just read straight through a file, whereas
Code:
RandomAccessFile
is meant to allow the developer to jump around the file at his/her whim.
 
This is what I ended up doing. I close the file. Then using the same object name I redefined the file, in essense I am reopening it. If you want to see code, I can post it later. Mike Wills
RPG Programmer (but learning Java)

"I am bad at math because God forgot to include math.h into my program!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top