When I run the following code:
int i = 0
try {
fstream = new FileWriter(filename);
BufferedWriter out = new BufferedWriter(fstream);
while (i < 100) {
out.write("My Name is Bobby Bob");
out.write(i);
out.newLine();
i++;
}
out.flush();
out.close();
} catch (IOException e) {
e.getClass();
}
I get the following in my output file:
My Name is Bobby Bob
x100
each one is followed by a weird symbol. Male sign, female sign etc etc.
My question is and its more of a curious one. What causes these weird symbols to appear? I was expecting numbers as it counted up. Where are these symbols pulled from?
out is a RandomAccessFile ?
I think you are using write(byte) instead of write(String), so you are writting the byte X, see ASCII TABLES for representations.
Try
Looking at BufferedWriter java api:
http://download.oracle.com/javase/1.4.2/docs/api/java/io/BufferedWriter.html#write(int)
it says that it writes the integer representation of a char, for your understanding.
If you want to print the value 0 you have to write 48 as this image represents:
