It's not a secret anymore!*
The moose likes Java in General and the fly likes How to check if file contents read matches what was written Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to check if file contents read matches what was written" Watch "How to check if file contents read matches what was written" New topic
Author

How to check if file contents read matches what was written

John Vorwald
Ranch Hand

Joined: Sep 26, 2010
Posts: 139
I would like to check if the data read from a file is the same as what was written.
Does the following example which calculating, saves, reads, recalculates, and compares the hash code accomplish the goal of making sure the data read matches the data written?
Is there a simpler solution?




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's actually pretty tough to read.

And what's up with your naming conventions? Does an "f" in front of a name mean something or not? If so, what on earth does it mean? What's the "a" prefix, in things like "aAValue"? What's with the comments of "Read data from a binary file" on a method named "readBinaryFile"? And naming an ObjectInputStream aIsObject? It's all quite distracting.

So, my two questions would be these: (a) does it do what you want, and (b) how could it be simpler than writing, reading, and comparing?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19799
    
  20

David Newton wrote:And what's up with your naming conventions? Does an "f" in front of a name mean something or not? If so, what on earth does it mean? What's the "a" prefix, in things like "aAValue"?

That's how some people name their variables: f for fields, a for arguments, nothing for local variables. I find it highly distracting too.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Rob Prime wrote:That's how some people name their variables: f for fields, a for arguments, nothing for local variables. I find it highly distracting too.

It's not very consistent in the code above, which is one reason I asked.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to check if file contents read matches what was written