This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The same data you wrote to the file! If you want to write a text file rather than a binary one (i.e. be able to read your file without a hex editor), use the Writer classes. Look at the Java Tutorial: IO for more info.
Question on efficiency here: what if I only print strings instead of dos.writeInt (seq); I'll say: dos.writeBytes (seq + ""); Effectively, my file would be a text file in the end (or good enough for what I need). Which is more efficient the Writer or Stream classes?
Well using dos.writeInt() will be more efficient, I'm pretty sure, but it's one of those situations where it's very unlikely you'll ever notice a difference unless you're writing a lot of data. Generally, the most important factor is how will you parse it? Using readInt() is pretty simple, if the data was written with writeInt(). Parsing text data can be more complexx, as you have to know more about the delimiters used in the file. But using a text format has one big advantage - humans can read and understand your file, just by looking at it. With bainary formats, they can't. So if you want humans to be able to do this, that often outweighs any other considerations.
"I'm not back." - Bill Harding, Twister
Joined: Jan 30, 2000
Note that you just wrote 456458. When the file is read, how will you no its not (4, 56458) or (4564, 58)? You probably need to insert some sort of delimiter.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com