counting no of bytes in a line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ushach
    New Member
    • Nov 2006
    • 17

    counting no of bytes in a line

    hi all,
    suppose an input file is of the form
    12 23 44 455 67 78 89
    12 33
    45 55 67 88 54 32 31
    2 4 5 6 7 8 88 999 00 22 1111 22 33 344 55 666 7777 88.
    how to count number of bytes in each line in this file?
    thanks in advance
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Read a line using a BufferedReader. Given the String (the line), call its
    getBytes() method and check the length of the array. Note that you cannot
    trust the length() method of the String object (the line) because it translates
    bytes into Unicode characters which doesn't matter much if your file only
    contains ASCII characters; for all other characters it does matter.

    Note that newline and/or carriage return characters are not included in the count.

    kind regards,

    Jos

    Comment

    Working...