Re: datainput stream

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 12/09/03


Date: Tue, 09 Dec 2003 21:20:05 GMT


"Amey Samant" <ameyas7@yahoo.com> wrote in message
news:669e50b8.0312091016.1d726b19@posting.google.com...
>
> > It is designed to read in a value which is encoded as a
> >binary integer. The values from 'System.in' are *not*
> > so-encoded, therefore you get what appear to be
> > random or nonsense values.
>
>
> > The data from 'System.in' is, instead, encoded as
> > characters. When performing interactive console
> > I/O you will find that input is merely a series of
> > characters terminated by the newline character.
>
> i did not follow this, i mean System.in is an object of
> InputStream which is ByteStream & not a character
> stream so what is your point ???
>

My point, and the only reason for my bothering to respond to your query, was
to help you solve your problem, and, as a by-product, help teach you a
little about streams.

Try the code I posted - it illustrates a known, efficient, and reliable
method for interactively extracting 'int' values from a character input
stream.

> > It's actually meant to decode data that was originally
> > written using a 'DataOutputStream' ! Although the results
> > look strange, it is behaving *exactly* as it should. The
> > problem, as mentioned earlier, is that the wrong type of
> > data has been supplied to 'readInt'.
>
>
http://java.sun.com/docs/books/tutorial/essential/io/example-1dot1/DataIODem
o.java
>
> this is an example from SUN s tutorial on I/O
> believe me when i downloaded this, compiled & run it DIDNT
> work the input read with readInt() appears like "?????"
> try it & let me know if you get the same thing
> i use WinXP , j2se 1.4.1_02
>

No, I don't have the time to conduct such experiments. I believe I've been
more than helpful:

* Posted useful code which you can modify and use
* Briefly described why you were experiencing such
   difficulties

I suggest that you re-read the tutorials noting the reasons why both stream
and reader [character stream] classes exist.

Anthony Borla



Relevant Pages

  • Re: "Read stuff from a file and chop it up to do stuff" code advice wanted.
    ... ;; This function returns TRUE if any character ... (if (char< char #\!) ... a stream and an array to hold characters in temp memory. ... ;; resulting string. ...
    (comp.lang.lisp)
  • Re: How to make Word STOP rewriting your copy
    ... The "character stream" that I was referring to is the GUI stream and not a physical storage stream (although I still believe the paragraph marker originally had it's roots there). ... the "power" of a tool can only be measured by how much PROODUCTIVE work can be done AT A GIVEN COST. ...
    (microsoft.public.mac.office.word)
  • Re: Read only last line-
    ... stream with a value that does not correspond to a position in the file ... example is putcon Windows, where one character ... That's the mapping you have to support. ... and fgetpos/fsetpos. ...
    (comp.lang.c)
  • Re: How do I stop a Winsock from buffering characters?
    ... it's applied at the OS level to the socket. ... Stream s = client.GetStream; ... from the client code and have the server see it right away. ... first character of the client send. ...
    (microsoft.public.windowsce.embedded)
  • Re: reading csv files
    ... >> stream, so, after the first name is extracted, the subsequent ... delimiter character, and not provide a complete solution to reading a CSV ... The next such call extracts 'yyyy', and ',', and the ...
    (alt.comp.lang.learn.c-cpp)