Hi to anyone who reads this I am trying to build 2 programs. The 1st program, called MailOrderWrite, is suppose to allow you to enter data and save it to a file called info.txt which seems to work fine as far as to my knowledge about Java programming. The 2nd program, called MailOrderRead, is suppose to grab the information from the txt file and display it appropriately in the two boxes. That is where I seem to be having my problem. Its displaying an odd result in only 1 of the boxes like 889193265. If anyone can help me I would appreciate it.
[ August 18, 2004: Message edited by: Matthew Buska ]
[ edited to break long lines and to remove the evil tab character -ds ] [ August 20, 2004: Message edited by: Dirk Schreckmann ]
You write a String to file. Lets say "123". It gets stored as a bunch of bytes (file contents in hex): 0003313233 You then try to read an int out of that file. Java doesn't care that you originally wrote a String. It's going to do what you tell it to do. Int's in Java are 32 bits, so we grab the first 32 bits out of the file: 00033132 hex or 209202 decimal. There you have it. A big weird number. But not random. It's what you asked for. So use the same read/write methods. Either read/writeUTF or read/writeInt. And get familiar with the Java Tutorial. In this case, the Chapter on DataInputStream would be particularly useful.
I guess readInt doesn't do what you think it does.
It does *not* read a String and parses it to an int.
It *does* instead read a fixed number of bytes and interpretes their bits as an int. That is, it can only read something that was written by writeInt beforehand.
Does that help?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
subject: What's up with a random number like this being displayed 889193265?