Counting characters from a file in java

[b][red]This message was edited by lockdown77 at 2007-1-30 9:19:4[/red][/b][hr]
I need help counting characters from a file. I know how to find the length of each word but i need to go through chaacter by character because i need to count spaces also. also need to count the number of lines. Any thoughts?


Comments

  • [b][red]This message was edited by Vilanye at 2007-1-30 9:34:47[/red][/b][hr]
    : [b][red]This message was edited by lockdown77 at 2007-1-30 9:19:4[/red][/b][hr]
    : I need help counting characters from a file. I know how to find the length of each word but i need to go through chaacter by character because i need to count spaces also. also need to count the number of lines. Any thoughts?
    :
    :

    A space is a character. If you read an entire line into a String and get the length, it will include spaces and other non-printing characters.






  • I'm not exactly sure how to read an entire line, and would you know how to count how many lines there are in a file.
  • : I'm not exactly sure how to read an entire line, and would you know how to count how many lines there are in a file.
    :
    With the BufferedReader class you can use the readLine() method to read an entire line. To count the number lines, use a while-loop to read the file, while maintaining an index of the line number. At the end of the loop, that index will be the number of lines.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories