• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use FileReader with datainputstream  RSS feed

 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to use the FileReader with the DataInputStream to read in characters from a text file (ex .4RDE.2CS.9WD ). I've never actually worked with files before, so I'm completely clueless on how to do it, or if it can be done the way I am trying to do it.

I am using the '.' as a dilimiter, when the byte is a '.' I want to skip to the next byte and use that as a counter. The byte after the counter is the byte I want to repeat based on the counter value.

So for exampe .4R would be RRRR (4R's) and the rest would be DECCSWWWWWWWWWD

Some problems I am having are:
- What encoding should I save my test file as? ASCI, Unicode, UTF-8?
- If I try to use readChar() on the first character it returns a '?' character, but if I use readByte() it returns back a '.'? Any help is appreciated, thanks.

This is the code I am using:

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used DataInputStream but it looks as though it's only going to work with a file that was written by DataOutputStream or happens to have exactly the right binary format. readInt Doc You may have to use an inputstream, read one char at a time and parse the length char into an int.

Your compression scheme is very familiar. I've done it with a 2 or 3 character length field and gotten very good compression on fixed length COBOL fields padded with zeros & spaces. Be sure to handle a "." in your data!
 
Bob Zoloman
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the moment I'm using the FileInputStream to try and read it in one one char or short at a time, I'm not sure if that's the one I should be using with the DataInputStream. Anything that works is fine by me

The compression is a running length encoding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!