How do I get the byte position of the first character in a line?? the first chracter byte position of each reader.readline???

How do I get the byte position of the first character in a line??  the first chracter byte position of each reader.readline???


  private static void displayTextInputStream(InputStream input)
    throws IOException {
          // Read one text line at a time and display.
        BufferedReader reader = new BufferedReader(new
                    InputStreamReader(input));
        while (true) {
            String line = reader.readLine();
            if (line == null) break;

            System.out.println("    " + line);
        }
        System.out.println();
    }
cbruneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krakatoaCommented:
String line = reader.readLine();

Each 'line' is a String. So the position of the first character in it will be 0 in the CharSequence array.
0
cbruneAuthor Commented:
I mean the overall byte mark of the starting character for the whole file
0
krakatoaCommented:
I mean the overall byte mark of the starting character for the whole file

What do you mean by "overall byte mark" ? The number of bytes will usually be the same as the number of characters in the file.
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

cbruneAuthor Commented:
if i need to skip to the beginning of a certain line in  the file.  as you are reading line by line I need the first byte position marker of where it is in the whole file so I can skip to that particular position.


"position here"test,test,test
"position here"test1,test1,test1
"position here"test2,test2,test2

So I can skip to the front of the line and read the whole record
0
krakatoaCommented:
Depends if your 'records' are all the same length. If they are then using a RandomAccessFile you can seek() to the correct starting offset. Otherwise your choices are to read in and count the lines, and stop when you reach the line you are looking for.

But your goal contains contradictions. You say that you want to "reading line by line", but then say you want to skip to that position. Well, once you've read in the lines, you will already be at that point, so you won't need to skip anywhere. Or . . . ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
What defines a "certain line"? How would the byte count be used to find it? There may be another method to accomplish what you need. If you could provide a little more description, perhaps with examples, of your requirement, it may help us with a solution.
0
krakatoaCommented:
Closed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.