My app reads text file line by line and record offset of each line until the end of file. But position() always returns 0. What is wrong with my code?
String buffer;
long offset;
RandomAccessFile raf = new RandomAccessFile("data.txt", "r");
FileChannel channel = raf.getChannel();
BufferedReader br = new BufferedReader(new InputStreamReader(Channels.newInputStream(channel)));
while (true) {
offset = channel.position(); // offset is always 0. why?
if ((buffer = br.readLine()) == null) // buffer has correct value.
return;
………………………………
}