My problem is:

  • I've try many times with DataOutputStream, FileWriter but I cannot write intergers into a file as I wanted.
  • I seemed to succeed but after writing them into a file, when I open it with notepad, I can read it. They all tuned out to many strange shape (such as ! # and square).

So is there any one can help me deal with my problem. For instance I want to write in such this format:

1 2 3


Use a BufferedWriter instead of DataOutputStream. You created a BufferedWriter like so:

BufferedWriter writer = new BufferedWriter( new FileWriter("myFile.txt") );

The tutorial that peter_budo linked should provide any other info you need on usage.

Thank you all very much indeed.

I've try PrintStream and superisingly, it's very easy.
I can use print() and println() as usual as printing to console.

I've made a worth experience and I hope my thread will be useful for some one.