File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to use FileReader with datainputstream Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "How to use FileReader with datainputstream" Watch "How to use FileReader with datainputstream" New topic
Author

How to use FileReader with datainputstream

Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
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

Joined: Jan 29, 2003
Posts: 8791
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!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Bob Zoloman
Ranch Hand

Joined: Jul 02, 2006
Posts: 72
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use FileReader with datainputstream
 
Similar Threads
"write end dead" or "pipe" broken error
Problem while using FileReader to read a file
Reading from a file
Need help with EOFException error
Java: Convert a binary file to "text" and back again.