How can I access ‘directly’ the data between 200th and 300th characters in a file in a secondary storage device?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a
java.io.RandomAccessFile. Pseudocode:Just add error-checking for robustness 😉
Oh, and you said you wanted to read characters, but file operations work on bytes. If you want to read characters then you have to worry about what the file encoding is. If the encoding is something like UTF-8 then you cannot just skip to a fixed byte index, because each UTF character can encode to a variable number of bytes. In this case you will just have to read the file from the start.