aspose file tools*
The moose likes I/O and Streams and the fly likes Problem on Counting Characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem on Counting Characters" Watch "Problem on Counting Characters" New topic
Forums: Beginning Java I/O and Streams
Author

Problem on Counting Characters

Anand Damodaran
Greenhorn

Joined: Oct 04, 2012
Posts: 21
Hi,



Input: JavaRanch // 9 + 1(for '\n')
But Output: 11


1> What is the 11th character? or is there any '\0' character?
2> Whether the read() used here, read characters from the keyboard BUFFER until NewLine Character is given ?


With respect,
Anand Damodaran

Anand Damodaran
Greenhorn

Joined: Oct 04, 2012
Posts: 21
Hi,

I found that characters '\u000D' - int value 13 and '\U000A'- int value 10(for '\n') were appended to the array of characters.

i.e., JavaRanch\u000D\U000A ,

so that i get 11.

What is the character value for \u000D? i get NewLine. is that True?


With respect,
Anand
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

Anand Damodaran wrote:What is the character value for \u000D? i get NewLine. is that True?

I think so, but the reason you're getting two characters (almost certainly) is that you're running the program on Windows, which uses the CRLF form for an end-of-line ('LF' stands for 'line feed' which, as I recall, is the same as a Unix newline).

Instead of using an InputStream, which is very low level, why not just use a Scanner (java.util.Scanner) and read in a line at a time? Then you won't have any of those annoying control characters to worry about.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39393
    
  28
Agree: the read() methods are low level and are not at all nice to work with.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42269
    
  64
And if that doesn't confuse you, consider this: http://weblogs.java.net/blog/tomwhite/archive/2005/03/counting_charac.html. Counting characters is actually more complicated if you can't rule out arbitrary characters.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem on Counting Characters