How to write integers into file?

B

b83503104

I want to write integers (with values around 0~500) into a file. But
the method write() of FileWriter seems to support only char, not int.
What am I supposed to do?
Thanks.
 
J

Joona I Palaste

b83503104 said:
I want to write integers (with values around 0~500) into a file. But
the method write() of FileWriter seems to support only char, not int.
What am I supposed to do?
Thanks.

Do you want to write the string representations of the integers to a
file? If so, look up Integer.toString(), then use the write(String)
method in FileWriter.
 
A

Andrew Thompson

I want to write integers (with values around 0~500) into a file. But
the method write() of FileWriter seems to support only char, not int.

I see three methods inherited from
OutputStreamWriter..
write(int)
write(char[],int,int)
write(String,int,int)

where did your see
write(char)?
What am I supposed to do?

Read the docs carefully.
<http://java.sun.com/j2se/1.4.2/docs...Writer.html#write(java.lang.String, int, int)>
<http://java.sun.com/j2se/1.4.2/docs/api/java/io/OutputStreamWriter.html#write(char[], int, int)>

And ..since this is c.l.j.programmer, you
_do_ know where to go from here, right?
 
R

Roedy Green

I want to write integers (with values around 0~500) into a file. But
the method write() of FileWriter seems to support only char, not int.
What am I supposed to do?

There are several things you might want to write:

binary ints, strings of human readable text separated by commas or
spaces, serialised objects ...

To see how to do each of these see the fileIO amanuensis:

http://mindprod.com/fileio.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top