It looks like you're confusing text (strings of characters) with
binary integers. You probably start out with a text file you created
containing the character '0' or '1', but when those are read into your
program as an integer, which is what Reader.read() returns, you get
the ASCII value (48 for '0', 49 for '1', etc.)
If you want the integer to be stored in the file as text (i.e. human
readable) then you have to convert from text to integer and
vice-versa. Keep in mind that Reader.read() will only read in one
character of an ASCII text file, so if your file contains the string
"302", then Reader.read() in your program will return the ASCII value
of '3' which is 51.
I would recommend you use a BufferedReader to read your file in with
the readLine() method, and a PrintWriter to write the file, using the
print(String s) or println(String s) method.
cyclone771@gmail.com wrote on 8 Oct 2005 11:07:26 -0700 in
comp.lang.java.programmer:
>I am beginning programming in Java, and I have created an application
>for a counter that adds 1 to a number stored in a file, then displays
[quoted text clipped - 20 lines]
> }
>}

Signature
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.
http://qform.sourceforge.net
If you're a musician, check out RPitch Relative Pitch
Ear Training Software.
http://rpitch.sourceforge.net
Dave Glasser - 08 Oct 2005 19:43 GMT
And PS, look up Integer.parseInt(String s) and String.valueOf(int n)
for info on doing the conversions.
Dave Glasser <dglasser@pobox.com> wrote on Sat, 08 Oct 2005 14:38:24
-0400 in comp.lang.java.programmer:
>It looks like you're confusing text (strings of characters) with
>binary integers. You probably start out with a text file you created
[quoted text clipped - 40 lines]
>> }
>>}

Signature
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.
http://qform.sourceforge.net
If you're a musician, check out RPitch Relative Pitch
Ear Training Software.
http://rpitch.sourceforge.net
>int x = in.read();
this is not how you read a number. You read a string, an entire
line, then convert to int.
To learn how to read the string see
http://mindprod.com/applets/fileio.html
for how to convert it to an int see
http://mindprod.com/applets/converter.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.