Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13854
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Need character output instead of numbers |
| Date | 2012-04-24 09:03 -0700 |
| Organization | Canadian Mind Products |
| Message-ID | <68jdp79qaa7409agltsp3t8r6ucbdrhl28@4ax.com> (permalink) |
| References | <jn4qae$5p1$1@dont-email.me> |
On Mon, 23 Apr 2012 16:58:05 -0700, bilsch <king621@comcast.net>
wrote, quoted or indirectly quoted someone who said :
>Here is a simple example of reading a text file as integers and
>displaying each with blank spaces in between.
It is hard to know where you are confused.
So I will just tell you some things:
public int read()
throws IOException
Reads the next byte of data from this input stream. The value byte is
returned as an int in the range 0 to 255. If no byte is available
because the end of the stream has been reached, the value -1 is
returned. This method blocks until input data is available, the end of
the stream is detected, or an exception is thrown.
Note how read() reads one unsigned byte but returns an int so that is
can use -1 as an eof marker.
See http://mindprod.com/applet/fileio.html
It will generate you code for pretty well any i/o purpose. Just tick
off the boxes what you want.
If you want to read binary 16 bit ints, you would use a
DataInputStream.readShort or readChar
To read 32 bit ints you would use readInt
>I looked at the input file with a hex editor and the ASCII chars are all
>stored as bytes - not integers.
That is to be expected. ASCII files are always just a series of
bytes. What did you hope to see?
>QUESTION 2) What do I need to do to get ASCII characters as output
instead of numbers?
An ASCII file is string of bytes. You can look at them as chars with a
text editor decimal bytes with a java progam like yours or hex bytes
with a hex editor. They are just bits.
If you are new to programming you may not have scaled the hump of
understanding the difference between a binary number representation
and a string of chars representation for the same value.
See http://mindprod.com/jgloss/binary.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Need character output instead of numbers bilsch <king621@comcast.net> - 2012-04-23 16:58 -0700
Re: Need character output instead of numbers Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-04-23 19:31 -0500
Re: Need character output instead of numbers Roedy Green <see_website@mindprod.com.invalid> - 2012-04-24 09:03 -0700
Re: Need character output instead of numbers Lew <lewbloch@gmail.com> - 2012-04-24 13:21 -0700
Re: Need character output instead of numbers bilsch <king621@comcast.net> - 2012-04-24 21:24 -0700
csiph-web