This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Explain the role of seek() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Explain the role of seek()" Watch "Explain the role of seek()" New topic
Author

Explain the role of seek()

Stephen Joseph
Ranch Hand

Joined: Dec 29, 2000
Posts: 50

Hello everyone
Please check this out.I want to know the exact role of the method seek() what does it do.Why is the output=20.
<code>
import java.io.*;
class SeekTest
{
public static void main(String args[])
{
try{
FileOutputStream fos = new FileOutputStream("xx");
for (byte b=10; b<50; b++)
fos.write(b);
fos.close();

RandomAccessFile raf = new RandomAccessFile("xx", "r");
raf.seek(10);
int i = raf.read();
raf.close();
System.out.println("i = " + i);
}

catch(FileNotFoundException ee)
{}

catch(IOException e)
{}

}
}
</code>

Thanks
Steven
Sandeep Jain
Ranch Hand

Joined: Oct 25, 2000
Posts: 124
Seek is like a position.in the file. what that statement nmeans is go to the 10 place and then read the data . All thge data before that will be skipped.

------------------
Sandeep Jain


Try and Try Till u succeed<br /> <br />Sandeep Jain
 
 
subject: Explain the role of seek()
 
Similar Threads
RHE - I/O Chapter Based Test
Help on file pointer after seek()
I/O
RandomAccessFIle
seek()