• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain the role of seek()

 
Stephen Joseph
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic