Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Looping an inputstream

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    25
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Looping an inputstream

    So I am trying to write some code that checks each char of an inputstream if it is a number and adds them up. I can handle most of it but it is just that I don't really understand inputstreams.

    I want to write a simple for loop for checking each char but I am not sure how I would check in input stream I was thinking something like:

    for(int i = 0; i < ???; i++){
         if(???? == [0-9]){
    I just don't know how I would put those parts in for an inputstream


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Looping an inputstream

    InputStreams work on bytes, not chars. If you want chars, you need to wrap your InputStream in an InputStreamReader. As you can see from the API docs for the read() method, it returns -1 when the end of stream is reached.

    Check out I/O Streams in the Java Tutorial for examples.

Similar Threads

  1. [SOLVED] InputStream to File
    By aussiemcgr in forum Java Theory & Questions
    Replies: 2
    Last Post: May 2nd, 2011, 01:05 PM
  2. Help in looping
    By endframe in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 28th, 2010, 03:24 PM
  3. need help looping with a string
    By beandip408 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 29th, 2010, 09:08 AM
  4. InputStream Problem at Client Side
    By pavan in forum Web Frameworks
    Replies: 1
    Last Post: March 26th, 2010, 03:21 AM
  5. [SOLVED] looping, for,while,do-while.
    By chronoz13 in forum Loops & Control Statements
    Replies: 4
    Last Post: August 6th, 2009, 01:32 PM

Tags for this Thread