• Post Reply Bookmark Topic Watch Topic
  • New Topic

InputStreamReader & reading bytes...  RSS feed

 
Ronnie McBob
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created an InputStreamReader to read ASCII characters from a file... this works fine. My problem is that the file also contains data that is encoded in other formats.. e.g. int or short or byte written by a DataOutputStream.

Any ideas how I can use my InputStreamReader to read characters and then read bytes? The InputStreamReader used a DataInputStream in its instanciation. Would be useful if I could get access to the underlying DataInputStream?

Any tips or help would be very useful!

Thanks!
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Chuddy. There are a few rules here that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Now, as for your question. It is a bad idea to mix Readers and In/OutputStreams. Readers are intended to be used with character-based files and Streams should be used with binary files. A good starting place for working with files is the Java Tutorial: Reading and Writing.
Is there any particular reason you are using an InputStreamReader to read your file?
 
Ronnie McBob
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe,

Have just changed the name to something a bit more realistic...

Anyway, thanks for the reply. I'm really just finding my way around the different packages. Have not had much experience in implementation.

Have decided to scrap the use of the reader now. I originally thought that I could only read the characters of "US-ASCII" type by using the reader.

Using the stream to read up bytes and then converting these to characters afterwards.

All is A-OK now


Thanks,

Ronnie McBob
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should take a gander at the documentation for DataInputStream. It has a convenitent readUTF() method which returns a String.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!