Fundamentally, this depends on the character encoding.
If you're using UTF-8 and have non-ASCII characters in your text, then a character offset tells you relatively little about the byte offset you'd have to seek to. (File systems are basically about bytes, not characters.)
However, if you're using a fixed-width encoding, you can simply multiple the character offset by the width of a character (in bytes) and then skip to the right part of the file, using InputStream.skip
:
- Construct a
FileInputStream
for the relevant file
- Skip to the right part of it
- Construct an
InputStreamReader
using the input stream - make sure you specify the encoding!
Again, if you're using a variable-width encoding such as UTF-8, you fundamentally don't get much information from the character offset.